Android Animation 帧动画监听结束的方法


这个问题用中文搜了很久一直没有解决,今天尝试用英文在Google上搜了一下,打开第一个网页就把困扰的很久的问题解决了

问题描述:帧动画连续播放--Android 帧动画没有提供结束动作的监听方法,怎么实现播放完一个动画之后接着播放第二个动画呢?

正确方法1:

  1. public void mmswoon(){  
  2.         imageView.setBackgroundResource(R.anim.mmswoon);  
  3.         AnimationDrawable animationDrawable = (AnimationDrawable)imageView.getBackground();  
  4.         animationDrawable.start();  
  5.           
  6.         int duration = 0;  
  7.         for(int i=0;i<animationDrawable.getNumberOfFrames();i++){  
  8.             duration += animationDrawable.getDuration(i);  
  9.         }  
  10.         Handler handler = new Handler();  
  11.         handler.postDelayed(new Runnable() {  
  12.             public void run() {  
  13.                //此处调用第二个动画播放方法     
  14.             }  
  15.         }, duration);  
  16.           
  17.     }  
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.   
  6.     //here I tried to implement option C but it didn't work   
  7.     while(correct_animation.isRunning()){  
  8.         try {  
  9.            Thread.sleep(20);  
  10.         } catch (InterruptedException e) {  
  11.            // TODO Auto-generated catch block   
  12.            e.printStackTrace();  
  13.         }  
  14.     }  
这个方法没有试过敲打

相关内容