Android自定义ProgressDialog进度等待框
来源:互联网 发布:张大宇数据 编辑:程序博客网 时间:2024/06/06 02:16
原文链接(建议跳转):http://www.jb51.net/article/77867.htm
今天我们来做一个请求网络时候的加载动画,如图:
1、要定义布局文件,该布局文件即是Dialog的布局了
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/dialog_view" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:minHeight="100dp" android:minWidth="190dp" android:orientation="vertical" android:padding="10dp" > <ImageView android:id="@+id/img" android:layout_width="60dp" android:layout_height="60dp" android:src="@drawable/loading" /> <TextView android:id="@+id/tipTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginTop="20dp" android:textColor="#acacac" android:textSize="15sp" /></LinearLayout>
2、定义动画,使得弹出框上的图片可以不停的旋转。
<?xml version="1.0" encoding="utf-8"?> <set android:shareInterpolator="false" xmlns:android="http://schemas.android.com/apk/res/android"> <rotate android:interpolator="@android:anim/linear_interpolator" android:pivotX="50%" android:pivotY="50%" android:fromDegrees="0" android:toDegrees="+360" android:duration="1500" android:startOffset="-1" android:repeatMode="restart" android:repeatCount="-1"/> </set>
3、实现自定义的Dialog逻辑
/** * 公用的弹出框 * * @author lining */public class LoadingDialog { /** * 得到自定义的progressDialog * * @param context * @param msg * @return */ public static Dialog createLoadingDialog(Context context, String msg) { // 首先得到整个View View view = LayoutInflater.from(context).inflate( R.layout.loading_dialog_view, null); // 获取整个布局 LinearLayout layout = (LinearLayout) view .findViewById(R.id.dialog_view); // 页面中的Img ImageView img = (ImageView) view.findViewById(R.id.img); // 页面中显示文本 TextView tipText = (TextView) view.findViewById(R.id.tipTextView); // 加载动画,动画用户使img图片不停的旋转 Animation animation = AnimationUtils.loadAnimation(context, R.anim.dialog_load_animation); // 显示动画 img.startAnimation(animation); // 显示文本 tipText.setText(msg); // 创建自定义样式的Dialog Dialog loadingDialog = new Dialog(context, R.style.loading_dialog); // 设置返回键返回 loadingDialog.setCancelable(true); //点击空白取消 loadingDialog.setCanceledOnTouchOutside(true); loadingDialog.setContentView(layout, new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)); return loadingDialog; }}
4、给自定义ProgressDialog设置一种样式
<!-- 自定义loading dialog --> <style name="loading_dialog" parent="android:style/Theme.Dialog"> <item name="android:windowFrame">@null</item> <item name="android:windowNoTitle">true</item> <item name="android:windowBackground">@color/block</item> <item name="android:windowIsFloating">true</item> <item name="android:windowContentOverlay">@null</item> </style>
5、使用自定义的ProgressDialog
private void showDialog() { if (dialog == null) { dialog = LoadingDialog.createLoadingDialog(this, "正在加载中..."); dialog.show(); dialog = null; } } private void closeDialog() { if (dialog != null) { dialog.dismiss(); dialog = null; } }
0 0
- Android自定义ProgressDialog进度等待框
- Android自定义ProgressDialog进度等待框
- 自定义ProgressDialog下载进度框
- 【android】自定义ProgressDialog实现暂时隐藏进度值并显示等待状态(附源码下载)
- android:自定义Material Design风格ProgressDialog的进度框
- Android进度对话框(ProgressDialog)
- ProgressDialog(等待框)
- android实践--进度对话框(ProgressDialog)
- Android自定义进度框
- android实现加载等待ProgressDialog
- android 实现progressdialog 等待界面
- Android ProgressDialog进度条 等待条
- android开发之美化版的ProgressDialog进度框
- Android ProgressDialog 自定义
- android 自定义progressDialog实现
- android 自定义progressDialog实现
- Android 自定义ProgressDialog
- Android 自定义progressDialog实现
- WebRTC Data Channels RFC
- Leetcode 100 : same Tree
- HDU-4339 Query(树状数组+二分)
- Linkedin工程师是如何优化他们的Java代码的
- NYOJ33--蛇形填数
- Android自定义ProgressDialog进度等待框
- 利用Qt的QDateTimeEdit设置起始时间(即开始时间大于结束时间)
- LINUX-内核-中断分析-中断向量表(1)-x86
- 大数相加+斐波那契数列(1)
- 转义字符以及类型的求取
- MySQL 1064 错误解决方法
- 【Leetcode】之Remove Duplicates from Sorted List II
- android sensor架构详解
- 2016/7/18