本文介绍了顺利进行ProgressBar更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用进度条(条形图)。我希望使用插补器使条形平滑增加和减少,但它不起作用。这就是我现在所拥有的:

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);             
pb.setProgress(pb.getProgress()+10);

我做错了什么?

推荐答案

Interpolator必须附加到动画上,这只适用于Honeycomb或更高版本:

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());
    animation.start();
}
else 
    seekbar.setProgress(progress); // no animation on Gingerbread or lower

如果您的最小SDK是Gingerbread或更低,请添加

If your minimum SDK is Gingerbread or lower, add

@TargetApi(Build.VERSION_CODES.HONEYCOMB) 
// or 
@SuppressLint("NewApi") 

到您的函数/类。

我用过一个DecelerateInterpolator,但这是可选的,还有其他可能性。

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

这篇关于顺利进行ProgressBar更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 06:45