如何使用动画的动画搜索栏动画、如何使用

2023-09-05 02:47:29 作者:庸俗且无趣

我是新来的机器人。我想动画的水平搜索栏,但不能做为止。 我只是想要一个动画中搜索栏显示了有些时间的进展说1分钟。 有人可以显示/给出出主意/ code。关于如何将我的动画的标准搜索栏片段?

I am new to android. I am trying to animate the horizontal seekbar but couldn't do so far. I just want an animation where seekbar shows the progress in some duration say 1 min. Can somebody suggest/give ideas/code snippet on how shall I animate the standard seekbar?

我应该用什么样的动画像objectanimator或valueAnimation? 我需要定义一个run方法(不知道!),以动画的拇指去下一个位置?

What kind of animation like objectanimator or valueAnimation shall I use? Do I need to define a run method (Not sure! ) to animate the thumb to go next position?

在此先感谢。

推荐答案

这样做的一个方法是使用ValueAnimator:

One way of doing it is by using a 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);
        }
    });

另一种方式可能是(还没有测试这一点):

Another way could be(havent test this):

final SeekBar seekBar =  findViewById(R.id.seekBar); 
ObjectAnimator anim = ObjectAnimator.ofFloat(seekBar, "progress", 0,seekBar.getMax());
anim.setDuration(10000);
anim.start();