使 ProgressBar 更新顺利 [英] Make a ProgressBar update smoothly

查看:30
本文介绍了使 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 has 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 更新顺利的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆