androidの自定义加载对话框ProgressDialog

1. 自定义ProgressDialog如图所示 androidの自定义加载对话框ProgressDialog_第1张图片
2 . 自定义组件,一般常见都是定义一个View类,继承自该组件看下源码:
public class CustomProgressDialog extends ProgressDialog {private AnimationDrawable mAnimation;private Context mContext;private ImageView mImageView;private String mLoadingTip;private TextView mLoadingTv;private int count = 0;private String oldLoadingTip;private int mResid;public CustomProgressDialog(Context context, String content, int id,int theme) {super(context, theme);this.mContext = context;this.mLoadingTip = content;this.mResid = id;setCanceledOnTouchOutside(true);}@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);initView();initData();}private void initView() {setContentView(R.layout.progress_dialog);mLoadingTv = (TextView) findViewById(R.id.loadingTv);mImageView = (ImageView) findViewById(R.id.loadingIv);}private void initData() {mImageView.setBackgroundResource(mResid);// 通过ImageView对象拿到背景显示的AnimationDrawablemAnimation = (AnimationDrawable) mImageView.getBackground();// 为了防止在onCreate方法中只显示第一帧的解决方案之一mImageView.post(new Runnable() {@Overridepublic void run() {mAnimation.start();}});mLoadingTv.setText(mLoadingTip);}}
我们会看到先定义一个构造方法, 此方法用来调用时候用于传值。 调用完构造方法后,会执行onCreate(), 加载一个xml布局文件。同时为该xml布局 组件赋值。 看下xml文件
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns: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" >    <ImageView        android:id="@+id/loadingIv"        android:layout_width="wrap_content"        android:layout_height="wrap_content" />    <TextView        android:id="@+id/loadingTv"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_alignBottom="@+id/loadingIv"        android:layout_centerHorizontal="true"        android:text="正在加载中.."        android:textSize="20sp" /></RelativeLayout>
这个布局文件其实很简单,就是一个图片跟一个TextView
在initData() 方法中,进行赋值情况,并执行动画。看起来很简单了。。这种自定义view ,结合xml 相对容易些。 最终就是调用即可
public void showmeidialog(){dialog=new CustomProgressDialog(this, "正在加载中",R.anim.frame,R.style.TRANSDIALOG);dialog.show();}


源码下载 点击打开链接
















更多相关文章

  1. 经典button布局
  2. Android获取系统时间的多种方法
  3. android camera 布局分析
  4. Android链式方法显示Dialog
  5. Android TextView 组件
  6. 【Android M】Monkey命令源码及是否处于monkey测试的判断方法
  7. Bugly Android 这个错误 Cleartext HTTP traffic to android.bug
  8. 使用组件构建Android应用程序

随机推荐

  1. Android处理scrollciew里嵌套ExpandableL
  2. 轮播网络图片加载适配
  3. android之RadioButton设置setChecked(tru
  4. android闹钟(五):实现闹钟功能
  5. android 图片与byte数组间的转换
  6. Android 显示网页图片
  7. android自动化测试[一]
  8. .NET和Android解压缩处理
  9. Android下横竖屏切换的处理
  10. Android代码实现飞行模式的打开