gpt4 book ai didi

java - 顺利进行 ProgressBar 更新

转载 作者:IT老高 更新时间:2023-10-28 20:29:30 27 4
gpt4 key购买 nike

我正在使用进度条(以条形形式)。我希望使用插值器平滑地增加和减少条形,但它不起作用。这是我目前拥有的:

pb.setInterpolator(main.this, android.R.anim.bounce_interpolator);             
pb.setProgress(pb.getProgress()+10);

我真的做错了吗?

最佳答案

插值器必须附加到动画上,这仅适用于 Honeycomb 或更高版本:

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 或更低版本,请添加:

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

到你的函数/类。

我使用了 DecelerateInterpolator,但这是可选的,还有其他可能性。

关于java - 顺利进行 ProgressBar 更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6097795/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com