上图: 本文代码GitHub地址

progress.gif
两个重点:
- 属性: ProgressBar的progressDrawable属性,实现圆形进度条
- 进度: ProgressBar的progress添加属性动画,并且addUpdateListener来监听当前进度
代码
- 属性progressDrawable的drawable:
circle_progress_bar.xml
- ProgressBar布局(当然也可以把ProgressBar拆出来单独使用):
- 给ProgressBar 添加updateListener:
objectAnimatorTop = ObjectAnimator
// 这里的animate的目标值是0,所以在updateListener我们获取到剩余的进度
// 改成progressBar.getMax(),获取到的就是正向的进度了
.ofInt(progressBarTop, "progress", 0)
.setDuration(MS_IN_FUTURE);
// 保证动画的插值器是线性的
objectAnimatorTop.setInterpolator(new LinearInterpolator());
objectAnimatorTop
.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
// 通过animated多少数值,来获取当前剩余的进度或者已经完成的进度
tvCountDownTop.setText(String.format("剩余\n%d"), (int) animation.getAnimatedValue()));
}
});
objectAnimatorTop.start();
使用
- 优点: 实现简单
- 缺点: 如果设定的total progress time相对于ProgressBar max progress比较长的话,会有断断续续的感觉
GitHub地址:
设计模式:
写在最后:
欢迎大家批评指正^_^