仿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(); ArrayListanimators = 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; } } }
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
分享文章:仿WP8样式的AndroidProgressBar-创新互联
链接URL:http://abwzjs.com/article/gjhei.html