I have a progress bar view like this:
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:max="100"/>
It lasts 3 second, so how to use interpolator to make update smoothly?
ObjectAnimator animation = ObjectAnimator.ofInt(what_is_in_here?);
animation.setDuration(3000); // second
animation.setInterpolator(new DecelerateInterpolator());
animation.start();
I really appreciate your help. Thank you very much in advance.
I found out the solution:
progressBar = (ProgressBar) findViewById(R.id.progress_bar);
ObjectAnimator animation = ObjectAnimator.ofInt(progressBar, "progress", 100, 0);
animation.setDuration(3500); // 3.5 second
animation.setInterpolator(new DecelerateInterpolator());
animation.start();
Here is a detailed explanation:
create an animation object:
ObjectAnimator animation = ObjectAnimator.ofInt(progressBar, "progress", 100, 0);
and set an interpolation:
animation.setInterpolator(new DecelerateInterpolator());
It is possible to use different interpolators for our animation, like for example:
DecelerateInterpolator: where the rate of change starts out quickly and and then decelerates.
AccelerateInterpolator: where the rate of change starts out slowly and and then accelerates.
OvershootInterpolator: where the change flings forward and overshoots the last value then comes back.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With