您的位置:首页 > 其它

自定义AnimationDrawable动画播放完监听

2013-03-28 14:55 701 查看
public abstract class CustomAnimationDrawableNew extends AnimationDrawable {

/** Handles the animation callback. */
Handler mAnimationHandler;

public CustomAnimationDrawableNew(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(new Runnable() {

public void run() {
onAnimationFinish();
}
}, 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();


}
http://stackoverflow.com/questions/2214735/android-animationdrawable-and-knowing-when-animation-ends
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: