title: How can I change the duration for an Android AnimationDrawable animation on-the-fly?
body: <p>I'm new to Android platform.  I'm using the following to animate a set of 16 "frames" using AminationDrawable in my app:</p>
  
  <p><strong>In the XML file I have:</strong></p>
  
  <pre><code>&lt;animation-list 
        xmlns:android="http://schemas.android.com/apk/res/android" 
        android:oneshot="false"&gt;
  &lt;item android:drawable="@drawable/image_1" android:duration="200" /&gt;
  &lt;item android:drawable="@drawable/image_1_25" android:duration="200" /&gt; 
  &lt;item android:drawable="@drawable/image_1_5" android:duration="200" /&gt;
  &lt;item android:drawable="@drawable/image_1_75" android:duration="200" /&gt; 
  &lt;item android:drawable="@drawable/image_2" android:duration="200" /&gt;
  &lt;item android:drawable="@drawable/image_2_25" android:duration="200" /&gt; 
  &lt;item android:drawable="@drawable/image_2_5" android:duration="200" /&gt;
  &lt;item android:drawable="@drawable/image_2_75" android:duration="200" /&gt;
  &lt;item android:drawable="@drawable/image_3" android:duration="200" /&gt;
  &lt;item android:drawable="@drawable/image_3_25" android:duration="200" /&gt; 
  &lt;item android:drawable="@drawable/image_3_5" android:duration="200" /&gt;
  &lt;item android:drawable="@drawable/image_3_75" android:duration="200" /&gt;
  &lt;item android:drawable="@drawable/image_4" android:duration="200" /&gt;
  &lt;item android:drawable="@drawable/image_4_25" android:duration="200" /&gt; 
  &lt;item android:drawable="@drawable/image_4_5" android:duration="200" /&gt;
  &lt;item android:drawable="@drawable/image_4_75" android:duration="200" /&gt; 
  &lt;/animation-list&gt;
  </code></pre>
  
  <p><strong>In the Java code I have the following</strong></p>
  
  <p>first I'm declaring the class and adding an <code>onCreate()</code> method where I set up the animation.</p>
  
  <pre><code>public class MyNewActivity extends Activity 
  {
      // member variables (accessible from within class methods below).
      AnimationDrawable mainAnimation;
      long mSpeed = 50;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) 
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.my_widget);
          // set up image
          ImageView mainImage = (ImageView) findViewById(R.id.image_widget);
          mainImage.setBackgroundResource(R.drawable.animated_image);
          mainAnimation = (AnimationDrawable) mainImage.getBackground();
      };
  &lt;...snip...&gt;
  </code></pre>
  
  <p>...then later on I start my drawing when the user presses a button I call the following to start the animation moving:</p>
  
  <pre><code>private void start()
  {
      // start the image rotating.
      if (mainAnimation.isRunning())
          mainAnimation.stop();
  
      int numFrames = mainAnimation.getNumberOfFrames();
      for (int ii = 0; ii &lt; numFrames; ii++ )
      {
          // change the animation speed.
          Drawable d = mainAnimation.getFrame(ii);
          mainAnimation.scheduleDrawable(d, mainAnimation, mSpeed);
      }
  }
  &lt;...snip...&gt;
  </code></pre>
  
  <p>So elsewhere in the code I have a place to adjust the member variable <code>mSpeed</code>.  If I do this and then call <code>start()</code>, the animation will start, however the speed is always the same (essentially what was defined in the XML above.  My question is, how can I modify the "duration" of the frames to move this animation faster/slower based on user input?  I see no way to modify a "duration" state, and was under the assumption the <code>ScheduleDrawable()</code> call above would change the drawing's frames duration.</p>