4

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();
Komal12
  • 3,340
  • 4
  • 16
  • 25
A2N
  • 150
  • 2
  • 13
  • 1
    It sounds like you'd rather want a `DecelerateInterpolator`. – Ben Mar 29 '18 at 10:45
  • 1
    **`ObjectAnimator progressAnimator = ObjectAnimator.ofInt(pbOption, "progress", 10000, 0);`** – AskNilesh Mar 29 '18 at 10:46
  • you need to implement custom interpolator. – Vladyslav Matviienko Mar 29 '18 at 10:48
  • 1
    Possible duplicate of [Make a ProgressBar update smoothly](https://stackoverflow.com/questions/6097795/make-a-progressbar-update-smoothly) – AskNilesh Mar 29 '18 at 10:54
  • https://www.google.co.in/search?q=fill+progress+bar+smoothly+with+animation+site:stackoverflow.com&client=ubuntu&hs=fBD&channel=fs&dcr=0&sa=X&ved=0ahUKEwiIt-yarZHaAhWMMo8KHfi2AvwQrQIIMygEMAA&biw=1600&bih=727 – AskNilesh Mar 29 '18 at 10:55
  • purpose of this question is about the progress bar animation not about smoothness since i have already achieved that @NileshRathod – A2N Apr 02 '18 at 08:44
  • ObjectAnimator progressAnimator = ObjectAnimator.ofInt(pbOption, "progress", 10000, 0); this shows "progress" parameter has some error. – A2N Apr 02 '18 at 08:45

2 Answers2

5

Change AccelerateInterpolator() to 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();
Ajay J G
  • 886
  • 7
  • 21
3

A super cute way of doing it on kotlin. based on @ajay-j-g 's answer

fun ProgressBar.smoothProgress(percent: Int){
    val animation = ObjectAnimator.ofInt(this, "progress", percent)
    animation.duration = 400
    animation.interpolator = DecelerateInterpolator()
    animation.start()
}

progressbar.smoothProgress(80)
Ian Elvister
  • 357
  • 3
  • 9