Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use animation to animate seekbar

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.

like image 416
Pallavi g Avatar asked Jun 02 '12 17:06

Pallavi g


1 Answers

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();
like image 145
Zelleriation Avatar answered Oct 22 '22 06:10

Zelleriation