学习自定义加载框
来源:互联网 发布:php 字符串 大括号 编辑:程序博客网 时间:2024/04/29 12:52
先自定义布局
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/load_llt" android:background="#000000" android:padding="15dp" android:gravity="center_horizontal" android:orientation="vertical" > <ImageView android:id="@+id/load_img" android:layout_width="150dp" android:layout_height="150dp" android:adjustViewBounds="true" android:src="@drawable/load_dialog" /> <TextView android:id="@+id/load_tv" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="正在加载中......" android:layout_marginTop="15dp" android:gravity="center_horizontal" android:textColor="#FFFFFF" android:textSize="20sp" /></LinearLayout>
加载的图片是网上随便找的:
设置图片的旋转动画
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false" > <rotate android:duration="2000" android:fromDegrees="0" android:interpolator="@android:anim/linear_interpolator" android:pivotX="50%" android:pivotY="50%" android:repeatCount="-1" android:repeatMode="restart" android:startOffset="-1" android:toDegrees="+360" > </rotate></set>
使用
LayoutInflater layoutInflater = LayoutInflater.from(this); View view = layoutInflater.inflate(R.layout.my_load_dialog, null);//获取布局 LinearLayout layout = (LinearLayout) view.findViewById(R.id.load_llt); ImageView imageView = (ImageView) view.findViewById(R.id.load_img); TextView tView = (TextView) view.findViewById(R.id.load_tv); Animation animation = AnimationUtils.loadAnimation(this, R.anim.load_anim); imageView.startAnimation(animation);//加载动画 Dialog loadDialog = new Dialog(this); loadDialog.setCancelable(true);//使返回键不作用与加载框 loadDialog.setCanceledOnTouchOutside(false);//点击框外框不消失 loadDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);//去除标题栏 loadDialog.setContentView(layout,new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT)); loadDialog.show();
自定义样式和封装
<item name="android:windowFrame">@null</item> <item name="android:windowNoTitle">true</item> <item name="android:windowIsFloating">true</item> <item name="android:windowContentOverlay">@null</item> </style>
如下封装:
/** * 显示加载框 * @param context * @return Dialog */ public Dialog showLoadDialog(Context context){ return showLoadDialog(context, ""); } /** * 显示加载框,更改消息显示 * @param context * @param showMessage * @return Dialog */ public Dialog showLoadDialog(Context context,String showMessage){ LayoutInflater layoutInflater = LayoutInflater.from(this); View view = layoutInflater.inflate(R.layout.my_load_dialog, null);//获取布局 LinearLayout layout = (LinearLayout) view.findViewById(R.id.load_llt); ImageView imageView = (ImageView) view.findViewById(R.id.load_img); TextView tView = (TextView) view.findViewById(R.id.load_tv); if (!showMessage.equals("")) { tView.setText(showMessage); } Animation animation = AnimationUtils.loadAnimation(context, R.anim.load_anim); imageView.startAnimation(animation);//加载动画 Dialog loadDialog = new Dialog(context,R.style.loading_dialog); loadDialog.setCancelable(true);//使返回键不作用与加载框 loadDialog.setCanceledOnTouchOutside(false);//点击框外框不消失 loadDialog.setContentView(layout,new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT)); loadDialog.show(); return loadDialog; }
0 0
- 学习自定义加载框
- ansj_seg 学习,自定义词典加载
- android自定义加载框
- android自定义加载框
- android自定义加载框
- 自定义加载框
- Android 自定义加载框
- android学习-----自定义View 加载动画
- 自定义加载框(2)
- 自定义旋转的加载框
- Android 自定义加载框dialog
- android自定义加载旋转框
- 自定义 Android loading 加载框。
- Android 自定义加载进度框
- android学习 豆瓣 自定义Progressbar 异步任务加载数据等
- 学习自定义View(一)实现进度条加载
- 学习自定义View(二)仿58同城加载
- 自定义加载等待框(MBProgressHUD)
- 如何清空并更新ListCtrl列表视图中的数据
- Hibernate4注解详解之一对多对象映射
- 照片视频制作软件
- Spring Security的filter配置及说明
- AMQP and Nova
- 学习自定义加载框
- 将assets文件夹下 person.db 复制到SD卡指定路径
- 按两次返回键退出
- 数据结构的选择-“数组、链表、树、哈希表”选哪个(性能比较)?
- python汇 安装问题
- ACM竞赛之新人向导(收藏)
- threadLocal线程安全介绍
- 异常总结
- goagent更新