view raw
Todd Davies Todd Davies - 10 months ago 257
Android Question

Android: make a progress bar update smoothly

I'm using a progress bar (in bar form). I wish to make the bar increase and decrease smoothly using an interpolator, but It's not working. This is what I have at the moment:

pb.setInterpolator(main.this, android.R.anim.bounce_interpolator);


Am I doing something really wrong?


The Interpolator have to be attached to an animation and this will work only on Honeycomb or higher :

if(android.os.Build.VERSION.SDK_INT >= 11){
    // will update the "progress" propriety of seekbar until it reaches progress
    ObjectAnimator animation = ObjectAnimator.ofInt(seekbar, "progress", progress); 
    animation.setDuration(500); // 0.5 second
    animation.setInterpolator(new DecelerateInterpolator());
    seekbar.setProgress(progress); // no animation on Gingerbread or lower

If your minimum SDK is Gingerbread or lower, add

// or 

to your function/class.

I used a DecelerateInterpolator, but this is optional and there are others possibilities.