Android实现Zaker的加载对话框

 

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

 

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值