CustomProgressDialog // 主要实现

/****@authoralexwan**/publicclassCustomProgressDialogextendsProgressDialog{privatestaticImageViewmImageView;//加载时显示的消息privateStringmLoadMsg;//privateTextViewmLoadingTv;//图片数组idprivatestaticint[]mIds;//当前图片indexprivatestaticintindex=0;privateCustomProgressDialog(Contextcontext,Stringcontent,int[]ids){super(context);this.mLoadMsg=content;CustomProgressDialog.mIds=ids;setCanceledOnTouchOutside(true);}/***获取CustomProgressDialog实例*@paramcontext上下文*@paramcontent加载显示的消息*@paramids图片数组*@return*/publicstaticCustomProgressDialoggetInstance(Contextcontext,Stringcontent,int[]ids){returnnewCustomProgressDialog(context,content,ids);}@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.progress_dialog);mLoadingTv=(TextView)findViewById(R.id.loadingTv);mLoadingTv.setText(mLoadMsg);mImageView=(ImageView)findViewById(R.id.loadingIv);initData();}privatevoidinitData(){try{//mImageView.setBackgroundResource(mIds[index]);}catch(Exceptione){e.printStackTrace();}}@Overridepublicvoidshow(){super.show();if(mIds.length>0){handler.sendEmptyMessage(1);}}@Overridepublicvoiddismiss(){super.dismiss();handler.sendEmptyMessage(2);}privatefinalstaticHandlerhandler=newHandler(){@OverridepublicvoidhandleMessage(Messagemsg){intwhat=msg.what;switch(what){case1:index++;if(index>=mIds.length){//图片的索引置为0index=0;}try{mImageView.setBackgroundResource(mIds[index]);}catch(Exceptione){e.printStackTrace();}handler.sendEmptyMessageDelayed(1,50);break;case2://移除加载下个动画的handlerhandler.removeMessages(1);index=0;break;default:break;}super.handleMessage(msg);}};}

Xml布局文件

<?xmlversion="1.0"encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:orientation="vertical"><ImageViewandroid:id="@+id/loadingIv"android:layout_width="wrap_content"android:layout_height="wrap_content"/><TextViewandroid:id="@+id/loadingTv"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignBottom="@+id/loadingIv"android:layout_centerHorizontal="true"android:textSize="20sp"android:text="努力加载中.."/></RelativeLayout>

应用

mProgressDialog=CustomProgressDialog.getInstance(this,"正在加载中",newint[]{R.drawable.cat_0001,R.drawable.cat_0002,R.drawable.cat_0003,R.drawable.cat_0004,R.drawable.cat_0005,R.drawable.cat_0006,R.drawable.cat_0007,R.drawable.cat_0008,R.drawable.cat_0009,R.drawable.cat_0010,R.drawable.cat_0011,R.drawable.cat_0012,R.drawable.cat_0013,R.drawable.cat_0014,R.drawable.cat_0015,R.drawable.cat_0016,R.drawable.cat_0017,R.drawable.cat_0018,R.drawable.cat_0019,R.drawable.cat_0020,R.drawable.cat_0021,R.drawable.cat_0022,R.drawable.cat_0023,});


更多相关文章

  1. 适配 Android10 内部存储图片显示问题
  2. 图片旋转的两种方法
  3. Android 仿网易一元夺宝客户端下拉加载动画实现(一)
  4. Android 使用颜色矩阵改变图片颜色,透明度,亮度
  5. android 显示gif格式的图片
  6. 详细讲解Android的图片下载框架UniversialImageLoader之磁盘缓存
  7. OOM的出现及解决(加载图片)
  8. 【Android 开发】:UI控件之 ImageView 实现适屏和裁剪图片的功能
  9. Android底下多线程下载远程图片

随机推荐

  1. Android 6.0 运行时权限 处理
  2. C# android base-64 字符数组的无效长度
  3. 淘宝(阿里百川)手机客户端开发日记第二篇
  4. Java jni 开发
  5. Android06_Android中常用控件
  6. 3G名家大讲堂:从Android和Windows Phone 7
  7. android基于http通信的库
  8. android菜单的使用
  9. 根据Android架构分层推荐开发书籍
  10. Android 中的通知