1. 程式人生 > >AnimationDrawable回到初始狀態(重置)

AnimationDrawable回到初始狀態(重置)

用AnimationDrawable的時候發現只有start()和stop(),但是需要把動畫重新返回初始狀態的時候怎麼辦?

解決方法1:

((AnimationDrawable)(someButton.getBackground())).stop();
someButton.setBackgroundDrawable(null);
someButton.setBackgroundResource(R.drawable.animation);
someButton.setBackgroundDrawable(null);這句會kill掉view的背景的動畫

解決方法2:

timerAnimation.stop();
timerAnimation.selectDrawable(0
);

回到第一幀