如何使用动画对搜索栏进行动画处理



我是安卓新手。我正在尝试对水平搜索栏进行动画处理,但到目前为止无法做到。我只想要一个动画,其中搜索栏显示某个持续时间(例如 1 分钟)的进度。有人可以建议/提供关于如何对标准搜索栏进行动画处理的想法/代码片段吗?

我应该使用什么样的动画,如对象动画器或值动画?我是否需要定义一个运行方法(不确定!)来对拇指进行动画处理以转到下一个位置?

提前谢谢。

一种方法是使用 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();

最新更新