我需要知道一次完成的AnimationDrawable何时完成,而不必将AnimationDrawable子类化,因为我必须以XML设置动画列表。我写了这个课,并在Gingerbread和ICS上进行了测试。它可以很容易地扩展以在每个帧上提供回调。
/**
* Provides a callback when a non-looping {@link AnimationDrawable} completes its animation sequence. More precisely,
* {@link #onAnimationComplete()} is triggered when {@link View#invalidateDrawable(Drawable)} has been called on the
* last frame.
*
* @author Benedict Lau
*/
public abstract class AnimationDrawableCallback implements Callback {
/**
* The last frame of {@link Drawable} in the {@link AnimationDrawable}.
*/
private Drawable mLastFrame;
/**
* The client's {@link Callback} implementation. All calls are proxied to this wrapped {@link Callback}
* implementation after intercepting the events we need.
*/