- 该网络加载等待提示框是一个utils,该加载框是通过继承Dialog的方式实现,在使用时只需通过Dialog.Show()方法进行该控件的显示,通过Dialog. dismiss()方法进行控件的隐藏
- 该加载框无需修改其他布局
- 加载框的效果通过动画实现
–代码实现
1.首先创建一个类让该类继承Dialog
2.具体代码实现
public class LoadingDialog extends Dialog {
public LoadingDialog(Context context) {
super(context, R.style.loadingDialogStyle);
}
private LoadingDialog(Context context, int theme) {
super(context, theme);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//加载布局
setContentView(R.layout.dialog_loading);
ImageView imageView = (ImageView) findViewById(R.id.login_anim);
//通过View的 getBackground得到AnimationDrawable对象
AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getBackground();
//开启动画
animationDrawable.start();
}
}
- 布局中的代码(res/layout/dialog_loading)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/LinearLayout"
android:layout_width="80dp"
android:layout_height="80dp"
android:background="@drawable/myprogress"
android:gravity="center"
android:orientation="vertical"
>
<ImageView
android:id="@+id/login_anim"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/anim_login"
/>
<!--@drawable/anim_login为一个补间动画 ->
</LinearLayout>
</LinearLayout>
- 动画效果实现(res/drawable/anim_login)
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false"
>
<!-- android:oneshot="false" 是否只播放一次 true 是 false 无限播放-->
<!--android:drawable="@drawable/a" 图片路径-->
<!-- android:duration="200" 事件-->
<item android:drawable="@drawable/a" android:duration="200"/>
<item android:drawable="@drawable/b" android:duration="200"/>
<item android:drawable="@drawable/c" android:duration="200"/>
<item android:drawable="@drawable/d" android:duration="200"/>
<item android:drawable="@drawable/e" android:duration="200"/>
<item android:drawable="@drawable/f" android:duration="200"/>
<item android:drawable="@drawable/g" android:duration="200"/>
<item android:drawable="@drawable/h" android:duration="200"/>
<item android:drawable="@drawable/i" android:duration="200"/>
<item android:drawable="@drawable/j" android:duration="200"/>
<item android:drawable="@drawable/k" android:duration="200"/>
<item android:drawable="@drawable/l" android:duration="200"/>
</animation-list>
图片就不上传了这里还可以进行其他动画的设置