我是android新手。我试图为水平搜索栏设置动画但是无法做到这一点。 我只想要一个动画,其中搜索栏在一段时间内显示进度,比如1分钟。 有人可以建议/给出关于如何为标准搜索栏设置动画的想法/代码片段吗?
我应该使用像objectanimator或valueAnimation这样的动画? 我是否需要定义一个run方法(不确定!)来为拇指设置动画以进入下一个位置?
提前致谢。
答案 0 :(得分:13)
这样做的一种方法是使用ValueAnimator:
final SeekBar seekBar = findViewById(R.id.seekBar);
ValueAnimator anim = ValueAnimator.ofInt(0,seekBar.getMax());
anim.setDuration(1000);
anim.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
int animProgress = (Integer) animation.getAnimatedValue();
seekBar.setProgress(animProgress);
}
});
另一种方式可能是(没有测试过这个):
final SeekBar seekBar = findViewById(R.id.seekBar);
ObjectAnimator anim = ObjectAnimator.ofFloat(seekBar, "progress", 0,seekBar.getMax());
anim.setDuration(10000);
anim.start();