如何使用动画平滑地填充进度条

4

我已经使用填充动画实现了进度条,但我希望有一个像火车一样的动画效果,它会快速填充到一个特定的点,然后在接近终点时减慢速度。我的当前动画实现是:

ObjectAnimator animation = ObjectAnimator.ofInt(pbOption, "progress", percent);
animation.setDuration(1250);
animation.setInterpolator(new AccelerateInterpolator());
animation.start();

1
听起来你更想要一个“减速插值器(DecelerateInterpolator)”。 - Ben
1
ObjectAnimator progressAnimator = ObjectAnimator.ofInt(pbOption, "progress", 10000, 0);对象动画器 progressAnimator,将 pbOption 对象的 progress 属性从 10000 变化到 0。 - AskNilesh
你需要实现自定义插值器。 - Vladyslav Matviienko
1
可能是使进度条平滑更新的重复问题。 - AskNilesh
显示剩余2条评论
2个回答

5

将AccelerateInterpolator()更改为DecelerateInterpolator()。 这里的变化速率开始很快,然后减慢。

   ObjectAnimator animation = ObjectAnimator.ofInt(pbOption, "progress", percent);
            animation.setDuration(1250);
            animation.setInterpolator(new DecelerateInterpolator());
            animation.start();

2
AccelerateDecelerateInterpolator() 做得更好! - A2N
我想要完整的带有进度条的代码来集成。请提供。 - Manmohan Soni

3
使用 Kotlin 实现一种超可爱的方法。基于 @ajay-j-g 的回答。
fun ProgressBar.smoothProgress(percent: Int){
    val animation = ObjectAnimator.ofInt(this, "progress", percent)
    animation.duration = 400
    animation.interpolator = DecelerateInterpolator()
    animation.start()
}

progressbar.smoothProgress(80)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接