尝试:
YourAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) { }
@Override
public void onAnimationEnd(Animation animation) {
//Ended
}
@Override
public void onAnimationRepeat(Animation animation) { }
});
编辑:哎呀。没有阅读可绘制部分。这是我用来检查所有帧是否都结束的递归函数:
private void checkIfAnimationDone(AnimationDrawable anim){
final AnimationDrawable a = anim;
int timeBetweenChecks = 300;
Handler h = new Handler();
h.postDelayed(new Runnable(){
public void run(){
if (a.getCurrent() != a.getFrame(a.getNumberOfFrames() - 1)){
checkIfAnimationDone(a);
} else{
Toast.makeText(getApplicationContext(), "ANIMATION DONE!", Toast.LENGTH_SHORT).show();
}
}
}, timeBetweenChecks);
};
您还可以记录开始动画的时间,并将持续时间(您事先知道)添加到其中以获得结束时间。但是,这可能不准确,因为设置和启动动画也需要一些时间。