[英]How to fill progress bar smoothly with animation
I have implemented the progress bar with fill animation, but I would like to have a animation effect like a train and which would fill fast to a particular point and then a bit slow brake in the speed till the end point.我已经实现了带有填充动画的进度条,但我想要一个像火车一样的动画效果,它会快速填充到特定点,然后在速度上稍微减速直到终点。 My current animation implementation is:
我目前的动画实现是:
ObjectAnimator animation = ObjectAnimator.ofInt(pbOption, "progress", percent);
animation.setDuration(1250);
animation.setInterpolator(new AccelerateInterpolator());
animation.start();
Change AccelerateInterpolator() to DecelerateInterpolator().将 AccelerateInterpolator() 更改为 DecelerateInterpolator()。 Here the rate of change starts out quickly and and then decelerates.
在这里,变化率开始很快,然后减速。
ObjectAnimator animation = ObjectAnimator.ofInt(pbOption, "progress", percent);
animation.setDuration(1250);
animation.setInterpolator(new DecelerateInterpolator());
animation.start();
A super cute way of doing it on kotlin.在 kotlin 上做这件事的一种超级可爱的方式。 based on @ajay-jg 's answer
基于@ajay-jg 的回答
fun ProgressBar.smoothProgress(percent: Int){
val animation = ObjectAnimator.ofInt(this, "progress", percent)
animation.duration = 400
animation.interpolator = DecelerateInterpolator()
animation.start()
}
progressbar.smoothProgress(80)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.