登陸的進度條android
1.通常因爲網絡下載數據須要必定的時間,因此咱們就要使用進度條。windows
先看看代碼:就這幾行就好了網絡
private void startProgressDialog() {
if (progressDialog == null) {
progressDialog = CustomProgressDialog.createDialog(this);
progressDialog.setMessage("正在加載中...");
}
progressDialog.show();
}
2.咱們看看windows的一些屬性
public class CustomProgressDialog extends Dialog {
private Context mContext = null;
private static CustomProgressDialog customProgressDialog = null;
public CustomProgressDialog(Context context) {
super(context);
this.mContext = context;
}
public CustomProgressDialog(Context context, int thieme) {
super(context, thieme);
this.mContext = context;
}
public static CustomProgressDialog createDialog(Context context) {
customProgressDialog = new CustomProgressDialog(context, R.style.CustomProgressDialog);
customProgressDialog.setContentView(R.layout.view_loadng);
customProgressDialog.setCanceledOnTouchOutside(false);
customProgressDialog.getWindow().getAttributes().gravity = Gravity.CENTER;
return customProgressDialog;
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (customProgressDialog == null) {
return;
}
ImageView imageView = (ImageView) customProgressDialog.findViewById(R.id.loadingImageView);
AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getBackground();
animationDrawable.start();
}
public CustomProgressDialog setMessage(String message) {
TextView tvmeg = (TextView) customProgressDialog.findViewById(R.id.id_tv_loadingmsg);
if (message != null) {
tvmeg.setText(message);
}
return customProgressDialog;
}
4.onWindowFocusChanged的做用ide
這個onWindowFocusChanged指的是這個Activity獲得或者失去焦點的時候 就會call。。
也就是說 若是你想要作一個Activity一加載完畢,就觸發什麼的話 徹底能夠用這個!!!動畫
使用一個view的getWidth() getHeight() 方法來獲取該view的寬和高,返回的值卻爲0。
若是這個view的長寬很肯定不爲0的話,那極可能是你過早的調用這些方法,也就是說在這個view被加入到rootview以前你就調用了這些方法,返回的值天然爲0.
解決該問題的方法有不少,主要就是延後調用這些方法。能夠試着在onWindowFocusChanged()裏面調用這些方法,驗證時能夠獲取到View的寬高的。this