问题
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