這個問題用中文搜了很久一直沒有解決,今天嘗試用英文在Google上搜了一下,開啟第一個網頁就把困擾的很久的問題解決了
問題描述:幀動畫連續播放--android 幀動畫沒有提供結束動作的監聽方法,怎麼實現播放完一個動畫之後接著播放第二個動畫呢?
正確方法1:
public void mmswoon(){
imageView.setBackgroundResource(R.anim.mmswoon);
AnimationDrawable animationDrawable = (AnimationDrawable)imageView.getBackground();
animationDrawable.start();
int duration = 0;
for(int i=0;i<animationDrawable.getNumberOfFrames();i++){
duration += animationDrawable.getDuration(i);
}
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
//此處調用第二個動畫播放方法
}
}, duration);
}
duration是第一個動畫播放的總時間
PS :自己試過了,可以實現效果
正確方法2:
this.q_pic_view.setImageResource(0);
this.q_pic_view.setBackgroundResource(R.drawable.animation_test);
AnimationDrawable correct_animation = (AnimationDrawable) this.q_pic_view.getBackground();
correct_animation.start();
//here I tried to implement option C but it didn't work
while(correct_animation.isRunning()){
try {
Thread.sleep(20);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
這個方法沒有試過
摘自 wangxin的專欄