通用模板 图片自己换。动图 = 多张静态图
frame_tyre.xml |
<?xml version="1.0" encoding="utf-8"?> <animation-list android:oneshot="false" xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/progress_loading_image_01" android:duration="50"/> <item android:drawable="@drawable/progress_loading_image_02" android:duration="50"/> <item android:drawable="@drawable/progress_loading_image_03" android:duration="50"/> <item android:drawable="@drawable/progress_loading_image_04" android:duration="50"/> </animation-list> |
布局 |
<LinearLayout android:id="@+id/anim_loading" android:layout_width="match_parent" android:orientation="vertical" android:gravity="center" android:layout_height="wrap_content"> <ImageView android:id="@+id/loadingIv" android:layout_width="35dp" android:layout_height="35dp" android:background="@drawable/frame_tyre"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="加载中……"/> </LinearLayout> |
具体使用 |
LinearLayout loadingLayout; AnimationDrawable mAnimation; ImageView mImageView; //-------启动动画------- public void startLoadingAnim(){ mImageView = (ImageView) view.findViewById(R.id.loadingIv); loadingLayout = (LinearLayout)view.findViewById(R.id.anim_loading); mImageView.setBackgroundResource(R.drawable.frame_tyre); mAnimation = (AnimationDrawable) mImageView.getBackground(); mImageView.post(new Runnable() { @Override public void run() { mAnimation.start(); } }); } //-------结束动画------- public void stopLoadingAnim(){ mAnimation.stop(); loadingLayout.setVisibility(View.GONE); } |