我有一个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();但是,我无法成功地将其恢复到原始状态,以便可以再次播放它。我该如何解决这个问题呢?
发布于 2018-10-27 20:10:44
你可以这样做:
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();发布于 2018-10-27 20:03:22
要获得可绘制文件的初始状态,可以使用animatedVectorDrawable.seekTo(0),您可以调用animatedVectorDrawable.stop()
https://stackoverflow.com/questions/53021667
复制相似问题