您好,我试图暂停动画 Drawable,但未能成功。在堆栈溢出的帮助下,我至少得到了 animationDrawable end listener 的帮助,这里是它的代码。是否有任何可能的方法可以暂停动画 Drawable 并从它暂停的位置开始...
public abstract class CustomAnimationDrawable extends AnimationDrawable{
/** Handles the animation callback. */
Handler mAnimationHandler;
Runnable r= new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
onAnimationFinish();
}
};
public CustomAnimationDrawable(AnimationDrawable aniDrawable) {
/* Add each frame to our animation drawable */
for (int i = 0; i < aniDrawable.getNumberOfFrames(); i++) {
this.addFrame(aniDrawable.getFrame(i), aniDrawable.getDuration(i));
}
}
@Override
public void start() {
super.start();
/*
* Call super.start() to call the base class start animation method.
* Then add a handler to call onAnimationFinish() when the total
* duration for the animation has passed
*/
mAnimationHandler = new Handler();
mAnimationHandler.postDelayed(r, getTotalDuration());
}
/**
* Gets the total duration of all frames.
*
* @return The total duration.
*/
public int getTotalDuration() {
int iDuration = 0;
for (int i = 0; i < this.getNumberOfFrames(); i++) {
iDuration += this.getDuration(i);
}
return iDuration;
}
/**
* Called when the animation finishes.
*/
abstract void onAnimationFinish();
public void destroy()
{
mAnimationHandler.removeCallbacksAndMessages(r);
mAnimationHandler.removeCallbacksAndMessages(null);
}
}
请帮助我有什么办法可以暂停吗?