歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android Animation 幀動畫監聽結束的方法

Android Animation 幀動畫監聽結束的方法

日期:2017/3/1 10:52:32   编辑:Linux編程

這個問題用中文搜了很久一直沒有解決,今天嘗試用英文在Google上搜了一下,打開第一個網頁就把困擾的很久的問題解決了

問題描述:幀動畫連續播放--Android 幀動畫沒有提供結束動作的監聽方法,怎麼實現播放完一個動畫之後接著播放第二個動畫呢?

正確方法1:

  1. public void mmswoon(){
  2. imageView.setBackgroundResource(R.anim.mmswoon);
  3. AnimationDrawable animationDrawable = (AnimationDrawable)imageView.getBackground();
  4. animationDrawable.start();
  5. int duration = 0;
  6. for(int i=0;i<animationDrawable.getNumberOfFrames();i++){
  7. duration += animationDrawable.getDuration(i);
  8. }
  9. Handler handler = new Handler();
  10. handler.postDelayed(new Runnable() {
  11. public void run() {
  12. //此處調用第二個動畫播放方法
  13. }
  14. }, duration);
  15. }
duration是第一個動畫播放的總時間

PS :自己試過了,可以實現效果

正確方法2:

  1. this.q_pic_view.setImageResource(0);
  2. this.q_pic_view.setBackgroundResource(R.drawable.animation_test);
  3. AnimationDrawable correct_animation = (AnimationDrawable) this.q_pic_view.getBackground();
  4. correct_animation.start();
  5. //here I tried to implement option C but it didn't work
  6. while(correct_animation.isRunning()){
  7. try {
  8. Thread.sleep(20);
  9. } catch (InterruptedException e) {
  10. // TODO Auto-generated catch block
  11. e.printStackTrace();
  12. }
  13. }
這個方法沒有試過
Copyright © Linux教程網 All Rights Reserved