Code example for AnimationDrawable

Methods: getDuration, getNumberOfFrames, selectDrawable

0
  /* Advances animation by one step, invalidates view, and queues next update */ 
  private Runnable animationStep = new Runnable() {
    private int idx = 0; 
 
    public void run() { 
      idx = (idx + 1) % animation.getNumberOfFrames(); 
      animation.selectDrawable(idx); 
      invalidate(); 
      postDelayed(this, animation.getDuration(idx)); 
    } 
  }; 
 
  private void triggerAnimation() { 
    // Remove existing animation "threads" if any 
    cancelAnimation(); 
    // Start a new animation loop 
    animation.selectDrawable(0);
    postDelayed(animationStep, animation.getDuration(0));
  } 
 
  private void cancelAnimation() {