一个WP8样式的进度对话框

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是ProgressBar显示的view,其实是一个包含了五个小蓝点的RelativeLayout,

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<Animator> animators = new ArrayList<Animator>();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();}// 先减速<span style="font-family: Arial, Helvetica, sans-serif;">,</span>再加速的插值器,<span style="font-family: Arial, Helvetica, sans-serif;">再停止一会儿。循环起来,就是WP8样式的加载进度</span>class DecelerateAccelerateStopInterpolator implementsandroid.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;}}}



更多相关文章

  1. Andorid Dialog 示例【慢慢更新】
  2. Android(安卓)之 下拉框(Spinner)的简单使用
  3. android listview custom style 自定义样式
  4. Android修改字体样式
  5. Android中的常用的对话框
  6. 样式 主题 对话框 国际化
  7. android绘图之Paint(1)
  8. DatePicker 日期选择控件 DatePickerDialog 日期选择对话框
  9. Android(安卓)设置没有 actionBar的 样式

随机推荐

  1. 关于android USB Host 串口编程
  2. Android开发9――Activity的启动模式
  3. android 7.0 关机流程详细分析
  4. Android的四种启动模式
  5. 技术转载:Android开发之常用代码片段
  6. android ndk开发中常用的系统自带网络命
  7. android ValueAnimator ObjectAnimator
  8. Android消息机制---Handler工作原理
  9. Android(安卓)架构概况,学习笔记。
  10. Color State List用于控件在各状态下的文