网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

仿WP8样式的AndroidProgressBar

一个WP8样式的进度对话框。对应Android转圈圈的ProgressBar。使用方法和普通的dialog一样

创新互联建站服务项目包括茶陵网站建设、茶陵网站制作、茶陵网页制作以及茶陵网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,茶陵网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到茶陵省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!

public class Win8ProgressDialog extends Dialog {
    private WPLoading loading;

    public Win8ProgressDialog(Context context) {
        super(context);
    }

    public Win8ProgressDialog(Context context, int theme) {
        super(context, theme);
    }

    public void setLoading(WPLoading loading) {
        this.loading = loading;
    }

    @Override
    public void cancel() {
        loading.cancel();
        super.cancel();
    }

    public Win8ProgressDialog(Context context, boolean cancelable,
            OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    public static class Builder {
        private Context mContext;
        private boolean canceledOnTouchOutside = true;
        private boolean cancelable = true;

        public Builder(Context context) {
            mContext = context;
        }

        public Builder setCanceledOnTouchOutside(boolean flag) {
            canceledOnTouchOutside = flag;
            return this;
        }

        public Builder setCancelable(boolean flag) {
            cancelable = flag;
            return this;
        }

        public Win8ProgressDialog create() {
            final Win8ProgressDialog dialog = new Win8ProgressDialog(mContext,
                    R.style.WPDialog);
            WPLoading loading = new WPLoading(mContext);
            dialog.setLoading(loading);
            dialog.setCancelable(cancelable);
            dialog.setCanceledOnTouchOutside(canceledOnTouchOutside);
            dialog.setCanceledOnTouchOutside(false);
            dialog.addContentView(loading, new LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
            loading.startAnimate();
            return dialog;
        }
    }

}

WPLoading是Win8ProgressDialog显示的view,其实是一个包含了运动五个小蓝点的RelativeLayout,小蓝点的动画使用了一个先减速后加速的插值器DecelerateAccelerateStopInterpolator

public class WPLoading extends RelativeLayout {

	private int size = 10;
	private int delay = 300;
	private int duration = 3200;
	private String color = "#0000ff";

	private AnimatorSet animatorSet = new AnimatorSet();

	public WPLoading(Context context) {
		super(context);
		LayoutParams params0 = new LayoutParams(
				DisplayUtil.getScreenWidth(context), size);
		View view = new View(context);
		view.setLayoutParams(params0);
		addView(view);
	}

	public void startAnimate() {
		LayoutParams params = new LayoutParams(size, size);
		animatorSet = new AnimatorSet();
		ArrayList animators = new ArrayList();
		for (int i = 0; i < 5; i++) {
			View view = new View(getContext());
			view.setBackgroundColor(Color.parseColor(color));
			addView(view);
			view.setLayoutParams(params);
			view.setX(-size);

			ObjectAnimator headAnimator = ObjectAnimator.ofFloat(view, "x",
					view.getX(), DisplayUtil.getScreenWidth(getContext()));
			headAnimator.setDuration(duration);
			headAnimator
					.setInterpolator(new DecelerateAccelerateStopInterpolator());
			headAnimator.setStartDelay(delay * i);
			headAnimator.setRepeatCount(-1);
			animators.add(headAnimator);
		}
		animatorSet.playTogether(animators);
		animatorSet.start();
	}

	public WPLoading(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public WPLoading(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	public void cancel() {
		animatorSet.end();
	}

	// 先减速再加速的插值器,在加速完成后会再停止一会儿,循环地进行这个动画,就和WP8的Loading样式一样了
	class DecelerateAccelerateStopInterpolator implements
			android.view.animation.Interpolator {
		private float mFactor = 1.0f;
		private float tailFactor = 0.6f;

		public DecelerateAccelerateStopInterpolator() {
		}

		public DecelerateAccelerateStopInterpolator(float factor) {
			mFactor = factor;
		}

		public float getInterpolation(float x) {
			float result;
			if (x > tailFactor) {
				result = 1;
			} else if (x > tailFactor / 2) {
				result = (float) Math.pow(
						(x - tailFactor / 2) * 2 / tailFactor, 2 * mFactor) / 2 + 0.5f;
			} else {
				result = (float) (1.0f - Math.pow((tailFactor - 2 * x)
						/ tailFactor, 2 * mFactor)) / 2;
			}
			return result;
		}
	}
}



网站名称:仿WP8样式的AndroidProgressBar
网站URL:http://bjjierui.cn/article/gjiocj.html

其他资讯