Android实现Zaker的加载对话框

来源:互联网 发布:js json 数组 map 编辑:程序博客网 时间:2024/05/20 01:10

 

仔细的看了看自己的博客上一篇写的博客的时间,发现好久好久没更新自己的博客了,主要是目前自己手上的这个外包项目太赶了,实在没太多的时间来更新呀,只能心有余而力不足呀。以后还是尽量的抽更多的时间来分享自己的一些学习方法或者自己胡乱搞的新东西,呵呵。废话不多说了,先进入今天要给大家分享的是一个定制的属于自己的Dialog。

这里要实现的是一个仿Zaker的等待对话框,相信用过Zaker的人也很多也比较熟悉了。

继续博客风格,先上效果图,再分析然后放源代码

 

实现的效果图:

 

 

对于Dialog的一些用法大家还不熟悉的可以上网自己搜索一下,其实要实现这样的一个效果很简单,无外乎就是继承了Dialog使用上了自己的布局和自己的主题。然后中间的那个旋转的刷新按钮就是一个旋转动画。好了不分析多了,相信聪明的你一看就懂,下面给出核心的代码:

 

结出核心的代码:

public class MyProgressDialog extends Dialog {private Context context = null;private TextView tv_msg;public MyProgressDialog(Context context) {super(context);this.context = context;}public MyProgressDialog(Context context, boolean cancelable,OnCancelListener cancelListener) {super(context, cancelable, cancelListener);this.context = context;// TODO Auto-generated constructor stub}public MyProgressDialog(Context context, int theme) {super(context, theme);this.context = context;// 加载自己定义的布局View view = LayoutInflater.from(context).inflate(R.layout.loading, null);ImageView img_loading = (ImageView) view.findViewById(R.id.img_loading);ImageView img_close = (ImageView) view.findViewById(R.id.img_close);tv_msg = (TextView) view.findViewById(R.id.tv_msg);// 加载XML文件中定义的动画RotateAnimation rotateAnimation = (RotateAnimation) AnimationUtils.loadAnimation(context, R.anim.rotate_refresh_drawable_default);// 开始动画img_loading.setAnimation(rotateAnimation);//为Dialoge设置自己定义的布局setContentView(view);//为close的那个文件添加事件img_close.setOnClickListener(new View.OnClickListener() {public void onClick(View v) {dismiss();}});}public void setMsg(String msg) {if (null != tv_msg) {tv_msg.setText(msg);}}public void setMsg(int resId) {if (null != tv_msg) {tv_msg.setText(context.getString(resId));}}}


旋转动画的文件:

<?xml version="1.0" encoding="utf-8"?><rotate xmlns:android="http://schemas.android.com/apk/res/android"    android:duration="800"    android:fromDegrees="0.0"    android:interpolator="@android:anim/linear_interpolator"    android:pivotX="50.0%"    android:pivotY="50.0%"    android:repeatCount="infinite"    android:toDegrees="360.0" />


在使用的Activity只要注意在使用的构造方法中要记得为其设置自己定义的主题

progressDialog = new MyProgressDialog(this,                R.style.CustomProgressDialog);


样式文件:

 <style name="CustomDialog" parent="@android:style/Theme.Dialog">        <item name="android:windowFrame">@null</item>        <item name="android:windowIsFloating">true</item>        <item name="android:windowContentOverlay">@null</item>        <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>        <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>    </style>    <style name="CustomProgressDialog" parent="@style/CustomDialog">        <item name="android:windowBackground">@android:color/transparent</item>        <item name="android:windowNoTitle">true</item>    </style>

好了,如此简单的一个功能就完成了。希望能对大家有点小小的帮助吧。


如需转载引用请注明出处:http://blog.csdn.net/jiahui524

 

 

原创粉丝点击