How to use animation to animate seekbar

自作多情 提交于 2019-12-30 08:59:07

问题


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?

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?

Thanks in advance.


回答1:


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


来源:https://stackoverflow.com/questions/10864388/how-to-use-animation-to-animate-seekbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!