Smooth Progress Bar Animation

前端 未结 9 835
鱼传尺愫
鱼传尺愫 2021-01-01 10:34

I\'m trying to implement a smooth animation for my ProgressBar, but when I increase the time (30 seconds), the animation is no longer smooth.

Example wi

9条回答
  •  悲&欢浪女
    2021-01-01 10:54

    If you change progress value each time by 1 (for example from 45 to 46) you won't see the animation. You'd better change progress by 100 points (or maybe other), for this you just need to multiply your max value by 100 and each progress value to 100 too. For example:

        private void setProgressMax(ProgressBar pb, int max) {
            pb.setMax(max * 100);
        }
    
        private void setProgressAnimate(ProgressBar pb, int progressTo) 
        {
            ObjectAnimator animation = ObjectAnimator.ofInt(pb, "progress", pb.getProgress(), progressTo * 100);
            animation.setDuration(500);
            animation.setInterpolator(new DecelerateInterpolator());
            animation.start();
        }
    

提交回复
热议问题