Reputation: 129
I have an AnimatedVectorDrawable that animates from play to pause state when clicked.
...
animatedVectorDrawable.registerAnimationCallback(new Animatable2.AnimationCallback() {
@Override
public void onAnimationEnd(Drawable drawable) {
//Reset the image back to its original state
//What I've tried so far
/* img.setImageResource(R.drawable.original_state)
animatedVectorDrawable.stop()
animatedVectorDrawable.reset() */
}
});
animatedVectorDrawable.start();
However, I've not been able to successfully get it back to its original state so that I can play it back again. How can I solve this?
Upvotes: 0
Views: 1050
Reputation: 13609
You could do like this:
final Handler mainHandler = new Handler(Looper.getMainLooper());
animatedVector.registerAnimationCallback(new Animatable2.AnimationCallback() {
@Override
public void onAnimationEnd(final Drawable drawable) {
mainHandler.post(new Runnable() {
@Override
public void run() {
animatedVectorDrawable.start();
}
});
}
});
animatedVectorDrawable.start();
Upvotes: 0
Reputation: 67
To get the initial state of the drawable use animatedVectorDrawable.seekTo(0)
and the you can call animatedVectorDrawable.stop()
Upvotes: -3