Android:如何使用Interpolator制作水平进度条?

我有一个这样的进度条视图:

 

 

<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:变化向前晃动并超过最后一个值然后返回.
>对于其他插补器,请检查接口android.view.animation.Interpolator.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值