- 該網絡加載等待提示框是一個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>
圖片就不上傳了這裏還可以進行其他動畫的設置