/** * @Description:自定义对话框 */public class MProgressDialog 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;/** *  * @param context *            上下文对象 * @param content *            显示文字提示信息内容 * @param id *            动画id */public <span style="font-family: Arial, Helvetica, sans-serif;">MProgressDialog</span>(Context context, String content, int id) {super(context);this.mContext = context;this.mLoadingTip = content;this.mResid = id;setCanceledOnTouchOutside(true);}@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);initView();initData();}private void initData() {mImageView.setBackgroundResource(mResid);// 通过ImageView对象拿到背景显示的AnimationDrawablemAnimation = (AnimationDrawable) mImageView.getBackground();mImageView.post(new Runnable() {@Overridepublic void run() {mAnimation.start();}});mLoadingTv.setText(mLoadingTip);}public void setContent(String str) {mLoadingTv.setText(str);}private void initView() {setContentView(R.layout.progress_dialog);// 显示界面mLoadingTv = (TextView) findViewById(R.id.loadingTv);mImageView = (ImageView) findViewById(R.id.loadingIv);}}
  


调用Activity代码:

public class ManActivity extends Activity {private MProgressDialog dialog;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout._progressdialog);}/** * 显示美团进度对话框 * @param v */public void showmeidialog(View v){dialog =new MProgressDialog(this, "正在加载中",R.anim.frame_animation);dialog.show();Handler handler =new Handler();handler.postDelayed(new Runnable() {@Overridepublic void run() {dialog.dismiss();}}, 3000);//3秒钟后调用dismiss方法隐藏;}}
  


R.anim.frame_animation 代码:就是两张动画图片

<?xml version="1.0" encoding="utf-8"?><animation-list xmlns:android="http://schemas.android.com/apk/res/android"    android:oneshot="false" >    <item        android:drawable="@drawable/progress_loading_image_01"        android:duration="150"/>    <item        android:drawable="@drawable/progress_loading_image_02"        android:duration="150"/></animation-list>

R.layout._progressdialog代码
<?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"        android:background="@anim/frame_animation"/>    <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:textSize="20sp"        android:text="正在加载中.." /></RelativeLayout>

就这样OK了。

更多相关文章

  1. Android(安卓)代码混淆exception解决办法
  2. kotlin如何使用FragmentPagerAdapter
  3. android app全屏显示
  4. AlertDialog对话框-自定义View
  5. Android编译环境配置
  6. DialogUtils Material风格对话框工具类
  7. 自定义弹窗,dialog
  8. android打电话简单功能(完整代码)
  9. 以Dialog方式显示activity

随机推荐

  1. SQL查询连续号码段的巧妙解法
  2. sql server中千万数量级分页存储过程代码
  3. 数据库分页存储过程代码
  4. sql基本函数大全
  5. SQL查询语句精华使用简要第1/2页
  6. 简单的SQL Server备份脚本代码
  7. SQL Server 数据库管理常用的SQL和T-SQL
  8. SQL SERVER的优化建议与方法
  9. SQL语言查询基础:连接查询 联合查询 代码
  10. 非常不错的SQL语句学习手册实例版第1/3页