`
mmdev
  • 浏览: 12950760 次
  • 性别: Icon_minigender_1
  • 来自: 大连
文章分类
社区版块
存档分类
最新评论

[转载]Android实现Zaker的加载对话框

 
阅读更多

http://blog.csdn.net/jiahui524转自

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



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


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





实现的效果图:








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





结出核心的代码:




[java] view plaincopyprint?
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));
}
}

}




旋转动画的文件:


[html] view plaincopyprint?
<?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只要注意在使用的构造方法中要记得为其设置自己定义的主题




[java] view plaincopyprint?
progressDialog = new MyProgressDialog(this,
R.style.CustomProgressDialog);




样式文件:


[html] view plaincopyprint?
<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>


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

相关推荐

Global site tag (gtag.js) - Google Analytics