1

I've implemented a circular progress bar that fills up in 10 seconds time. However, I think the bar fills up quicker in the beginning, and, as a result, it slows down (the animation of it filling) as the time goes on. In addition, at the end, it stops for moment and then finally finishes. The code I used I got from the first answer here: How to Create a circular progressbar in Android which rotates on it?

And then my code which starts the progress bar is:

ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar);
ObjectAnimator animation = ObjectAnimator.ofInt (progressBar, "progress", 0, 100);
animation.setDuration (10000);
animation.setInterpolator (new DecelerateInterpolator());
animation.start();

How can I make the animation smoother?

Community
  • 1
  • 1
Jill
  • 533
  • 7
  • 22
  • May be this could help [link](https://github.com/Pedramrn/CircularProgressBar) – jarvo69 Jul 27 '16 at 04:33
  • It seems like that would be a lot more code to achieve what I already have. I guess it'd be better if it were smoother, but I'd like to know why mine is having this problem. – Jill Jul 27 '16 at 04:36
  • 1
    its because of DecelerateInterpolator. Use LinearInterpolator instead. – dudego Jul 27 '16 at 04:38
  • 1
    You are using a `DecelerateInterpolator` which is meant to slow down any animation towards the end. What do you mean by smoother? I think [this tutorial](http://cogitolearning.co.uk/?p=1078) on interpolators could help you. – Ishita Sinha Jul 27 '16 at 04:38
  • oh. my. god...you guys are geniuses. Lol thanks!! – Jill Jul 27 '16 at 04:40
  • While I have your attention, my progress bar goes up only as a button is being held. Do you know how I can stop the progress and reset it to 0 if the button is released before the 10 second time limit is reached? – Jill Jul 27 '16 at 04:44

1 Answers1

4

This is because you are using DecelerateInterpolator. An interpolator defines the rate of change of an animation. This allows the basic animation effects to be accelerated, decelerated, repeated, etc.

You can read more about interpolator here.

You can either use LinearInterpolator or AccelerateInterpolator whichever serves your purpose.

Shunan
  • 3,165
  • 6
  • 28
  • 48