[英]Stop AnimatedVectorDrawable animation after playing
I have an AnimatedVectorDrawable that animates from play to pause state when clicked. 我有一个AnimatedVectorDrawable,可在单击时从播放动画到暂停状态。
...
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?
我该如何解决?
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();
要获取可绘制对象的初始状态,请使用animatedVectorDrawable.seekTo(0)
,然后您可以调用animatedVectorDrawable.stop()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.