gpt4 book ai didi

Android:如何使用插值器制作水平进度条?

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:54:24 24 4
gpt4 key购买 nike

我有一个这样的进度条 View :

<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:max="100"/>

持续3秒,那么如何使用插值器来平滑更新呢?

ObjectAnimator animation = ObjectAnimator.ofInt(what_is_in_here?); 
animation.setDuration(3000); // second
animation.setInterpolator(new DecelerateInterpolator());
animation.start();

非常感谢您的帮助。非常感谢您。

最佳答案

我找到了解决方案:

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();

详细解释如下:

创建一个动画对象:

ObjectAnimator animation = ObjectAnimator.ofInt(progressBar, "progress", 100, 0);
  • progressBar:引用布局中的ProgressBar;
  • "progress":要动画的属性名称;
  • 100:动画起点;
  • 0:动画的结束点。

并设置一个插值:

animation.setInterpolator(new DecelerateInterpolator());

可以为我们的动画使用不同的插值器,例如:

  • LinearInterpolator:其中变化率是恒定的。
  • DecelerateInterpolator:变化率开始时很快,然后减速。

  • AccelerateInterpolator:变化率开始缓慢然后加速。

  • OvershootInterpolator:变化向前冲过最后一个值然后返回。

  • 对于其他插值器检查接口(interface)android.view.animation.Interpolator.

关于Android:如何使用插值器制作水平进度条?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30472485/

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