登录的进度条动画的实现代码

                                                                      登录的进度条

1.一般由于网络下载数据需要一定的时间,所以我们就要使用进度条。

先看看代码:就这几行就行了

private void startProgressDialog() {
if (progressDialog == null) {
progressDialog = CustomProgressDialog.createDialog(this);
progressDialog.setMessage("正在加载中...");
}
progressDialog.show();
}

2.我们看看windows的一些属性
<item name="android:windowFrame">@null</item> :Dialog的windowFrame框为无
<item name="android:windowIsFloating">true</item>:是否浮现在activity之上
<item name="android:windowIsTranslucent">false</item>:是否半透明
<item name="android:windowNoTitle">true</item>:是否显示title
<item name="android:windowBackground">@drawable/dia_bg</item>:设置dialog的背景
<item name="android:backgroundDimEnabled">false</item>: 背景是否模糊显示这个是背景是否变暗
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>窗口动画风格
android:oneshot="false" >表示可以循环播放动画
 
 
3.
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的作用

这个onWindowFocusChanged指的是这个Activity得到或者失去焦点的时候 就会call。。
也就是说 如果你想要做一个Activity一加载完毕,就触发什么的话 完全可以用这个!!!

使用一个view的getWidth() getHeight() 方法来获取该view的宽和高,返回的值却为0。
如果这个view的长宽很确定不为0的话,那很可能是你过早的调用这些方法,也就是说在这个view被加入到rootview之前你就调用了这些方法,返回的值自然为0.
解决该问题的方法有很多,主要就是延后调用这些方法。可以试着在onWindowFocusChanged()里面调用这些方法,验证时可以获取到View的宽高的。

 

转载于:https://www.cnblogs.com/fcl13761179064/p/6841623.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值