ANDROID中自定义的加载对话框和加载条
2013-11-19 11:14
183 查看
先分享一个常用的转动形式加载对话框。
这个是很早前一个应用,一哥们写的控件。
后来发现联想的应用中基本所用应用加载框都是这个。(开源代码没版权一说吧)
控件比较简单,分享下思路:
1.首先这是一个自定义的dialog,重写了dialog,系统的progressdialog也是继承了dialog。
2.主要是setContentView(view)中的这个view该如何定义。
3.上面的核心代码就是那个style,下面我们看下这个style代码;
4.我们看第一个item,也就是不稳定的图片,也是关键代码。自定义的drawable,我们知道res下的drawable文件中可以定义多种样式的drawable资源文件,
比如常用的动画放大缩小平移资源,
还有设计按钮中常用的 selector选择器,以及我们现在用到的 animation-list。
四张图片,间隔时间为500毫秒。于是小花就转动起来了。
以上即是小花图ui设计思路。
下面在提下关于logo界面进入时,有时我们也会用到的一个加载动画效果:
比如:
这个纯粹是是一个ProgressBar,然后自定义了一下样式而已:
然后是drawable文件:
其实总觉得这样挺浪费资源的,一个加载条就要这么多图片资源。
以前也看到过说直接用一张图,然后类似于游戏中地图那样的切割法,在代码中动态剪彩和绘制。
有兴趣的可以尝试下。
原文:/article/1654113.html#
这个是很早前一个应用,一哥们写的控件。
后来发现联想的应用中基本所用应用加载框都是这个。(开源代码没版权一说吧)
控件比较简单,分享下思路:
1.首先这是一个自定义的dialog,重写了dialog,系统的progressdialog也是继承了dialog。
/** * @author Nono * */ public class CustomProgressBarDialog extends Dialog { private LayoutInflater inflater; private Context mContext; private LayoutParams lp; /** * @param context */ public CustomProgressBarDialog(Context context) { super(context, R.style.NoTitleDialog); this.mContext = context; inflater = (LayoutInflater) mContext .getSystemService(Context.LAYOUT_INFLATER_SERVICE); layout = inflater.inflate(R.layout.custom_progressbar, null); setContentView(layout); // 设置window属性 lp = getWindow().getAttributes(); lp.gravity = Gravity.CENTER; lp.dimAmount = 0; // 去背景遮盖 lp.alpha = 1.0f; getWindow().setAttributes(lp); } }
2.主要是setContentView(view)中的这个view该如何定义。
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center"> <ProgressBar xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" style="@style/CustomProgessBarStyle" android:padding="10dip" android:layout_gravity="center" android:gravity="center" /> <TextView android:id="@+id/load_info_text" android:text="@string/loading" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#FFFFFF" android:padding="10dip" /> </LinearLayout>
3.上面的核心代码就是那个style,下面我们看下这个style代码;
<style name="CustomProgessBarStyle"> <item name="android:indeterminateDrawable">@drawable/custom_progress_bar</item> <item name="android:minWidth">50dip</item> <item name="android:maxWidth">50dip</item> <item name="android:minHeight">50dip</item> <item name="android:maxHeight">50dip</item> </style>
4.我们看第一个item,也就是不稳定的图片,也是关键代码。自定义的drawable,我们知道res下的drawable文件中可以定义多种样式的drawable资源文件,
比如常用的动画放大缩小平移资源,
还有设计按钮中常用的 selector选择器,以及我们现在用到的 animation-list。
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false" android:visible="true"> <item android:drawable="@drawable/flower1" android:duration="500" /> <item android:drawable="@drawable/flower2" android:duration="500" /> <item android:drawable="@drawable/flower3" android:duration="500" /> <item android:drawable="@drawable/flower4" android:duration="500" /> </animation-list>
四张图片,间隔时间为500毫秒。于是小花就转动起来了。
以上即是小花图ui设计思路。
下面在提下关于logo界面进入时,有时我们也会用到的一个加载动画效果:
比如:
这个纯粹是是一个ProgressBar,然后自定义了一下样式而已:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:background="@drawable/lottery_main_bg" android:gravity="center" android:layout_height="fill_parent"> <ProgressBar android:indeterminateDrawable="@drawable/custom_progress_bar" android:layout_marginTop="30dip" android:indeterminate="false" android:id="@+id/CustomprogressBar" android:layout_width="225dip" android:layout_height="15dip" /> </LinearLayout>
然后是drawable文件:
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false" android:visible="true"> <item android:drawable="@drawable/load01" android:duration="200" /> <item android:drawable="@drawable/load02" android:duration="200" /> <item android:drawable="@drawable/load03" android:duration="200" /> <item android:drawable="@drawable/load04" android:duration="200" /> <item android:drawable="@drawable/load05" android:duration="200" /> <item android:drawable="@drawable/load06" android:duration="200" /> </animation-list>
其实总觉得这样挺浪费资源的,一个加载条就要这么多图片资源。
以前也看到过说直接用一张图,然后类似于游戏中地图那样的切割法,在代码中动态剪彩和绘制。
有兴趣的可以尝试下。
原文:/article/1654113.html#
相关文章推荐
- ANDROID类似于滚动的通知栏实现
- Android 代码自动提示功能
- Android学习笔记进阶19之给图片加边框
- Android学习笔记进阶20之得到图片的缩略图
- Android安装包apk文件在某些版本操作系统上安装解析包出错问题的解决办法
- Android学习笔记之详细讲解画圆角图片
- Android学习笔记进阶之在图片上涂鸦(能清屏)
- android 实现zip文件的解压
- Android 滑动切换页面-ViewFlipper
- Android异步消息处理机制完全解析,带你从源码的角度彻底理解
- android 性能优化
- Android4.2.2 Gallery2源码分析(1)——从布局入手 .
- Android中集成第三方软件包(.jar, .so)
- iOS的 context 和Android 中的 canvas
- Android获取ROOT权限的实例代码
- Android百度地图之显示地图
- Android的图片叠加
- Android TouchEvent 分发流程
- Android 获取下载文件的真实名字
- android中的单选和多选按钮的使用