title: Avoid onMeasure and onLayout everytime ImageView Bitmap is set
body: <p>This is my setup. I have a custom <code>ListView</code> with some fancy headers, which is inside a <code>ViewPager</code>. I'm maintaining a memory cache of images that having been downloaded and stored locally like any self-respecting developer would.</p>
  
  <p>The issue I'm having is that everytime I call <code>setImageBitmap(Bitmap bm)</code> on the <code>ImageView</code> in my <code>ListView</code>'s <code>getView()</code> method, using a Bitmap from the cache, it's causing my all Views to <code>onMeasure()</code>. I've looked through the Android <code>ImageView</code> source code and found this:</p>
  
  <pre><code>public void setImageDrawable(Drawable drawable) {
      if (mDrawable != drawable) {
          mResource = 0;
          mUri = null;
  
          int oldWidth = mDrawableWidth;
          int oldHeight = mDrawableHeight;
  
          updateDrawable(drawable);
  
          if (oldWidth != mDrawableWidth || oldHeight != mDrawableHeight) {
              requestLayout();
          }
          invalidate();
      }
  }
  </code></pre>
  
  <p>So I can see that <code>setImageDrawable</code> (which is called by <code>setImageBitmap</code>) requests its layout whenever the <code>drawable</code> has differing dimensions than its previous <code>Drawable</code>. The problem is that my <code>ImageView</code> is set static to 60dp x 60dp, so its size isn't going to change regardless of the size of its image.</p>
  
  <p>Is there a way I can get around the layouts being constantly remeasured as I scroll? The <code>onMeasure</code> and <code>onLayout</code> calls are propagating their way up the <code>View</code> tree, so my <code>ListView</code> and <code>ViewPager</code> are also getting measured in the middle of the list scrolling, which is obviously causing serious performance issues (~100ms UI jumps).</p>
  
  <p>The performance is awful and I need to correct it. Anyone have any solutions?</p>
  
  <p>Thanks.</p>