title: AnimationDrawable auto starts
body: <p>I have a problem with an <code>AnimationDrawable</code> that I create programatically that starts as soon as I assign it to an <code>ImageView</code> via <code>imageView.setBackgroundDrawable</code> (I support API 8).</p>
  
  <p>This is an abbreviation of my code:</p>
  
  <pre><code> mSequence = new AnimationDrawable();
   ImageView imageView = new ImageView(context);
   ImageView.setAdjustViewBounds(false);
  </code></pre>
  
  <p>All of my assets are saved locally so I add them to the <code>AnimationDrawable</code></p>
  
  <pre><code>for(String assetId : mAssets) {
      bitmap = loadBitmap(assetId); // returns a bitmap saved earlier
      if (bitmap != null) {
          mSequence.addFrame(new BitmapDrawable(res, bitmap), mFrameDuration);
      }
  }
  </code></pre>
  
  <p>And finally I assign the <code>AnimationDrawable</code> to the view</p>
  
  <pre><code>if (mSequence.getNumberOfFrames() &gt; 0) {
      imageView.setBackgroundDrawable(mSequence);
  }
  </code></pre>
  
  <p>Now before I have a chance to call the <code>start()</code> function the animation starts as soon as the <code>ImageView</code> is loaded.</p>
  
  <p>I want to be able to control when the animation starts according to my own logic.</p>
  
  <p>Has this happened to anyone?</p>
  
  <p>**</p>
  
  <h2>EDIT:</h2>
  
  <p>**</p>
  
  <p>Thanks to Tom, I know the reason for the triggering of the animation is the change in visibility that happens to the <code>ImageView</code> that actively happens after assigning the <code>AnimationDrawable</code>. The solution in my case isn't trivial since I have a complicated situation but for others it might be simpler.</p>
  
  <h2>EDIT 2:</h2>
  
  <p>I'm back to setting the drawable as the background according to <a href="http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html" rel="nofollow">class description</a>, and I quote:</p>
  
  <blockquote>
    <p>The simplest way to create a frame-by-frame animation is to define the
    animation in an XML file, placed in the res/drawable/ folder, and set
    it as the <strong>background</strong> to a View object. Then, call start() to run the
    animation.</p>
  </blockquote>