title: Android ImageView scale smaller image to width with flexible height without cropping or distortion
body: <p>Often asked, never answered (at least not in a reproducible way).</p>
  
  <p>I have an image view with an image that is <strong>smaller</strong> than the view. I want to scale the image to the width of the screen and adjust the height of the ImageView to reflect the proportionally correct height of the image.</p>
  
  <pre><code>&lt;ImageView
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
  /&gt;
  </code></pre>
  
  <p>This results in the image centered at its original size (smaller then the screen width) with margins at the side. No good.</p>
  
  <p>So I added</p>
  
  <pre><code>android:adjustViewBounds="true" 
  </code></pre>
  
  <p>Same effect, no good. I added</p>
  
  <pre><code>android:scaleType="centerInside"
  </code></pre>
  
  <p>Same effect, no good. I changed <code>centerInside</code> to <code>fitCenter</code>. Same effect, no good. I changed <code>centerInside</code> to <code>centerCrop</code>. </p>
  
  <pre><code>android:scaleType="centerCrop"
  </code></pre>
  
  <p>Now, finally, the image is <strong>scaled</strong> to the width of the screen - but <strong>cropped</strong> at top and bottom! So I changed <code>centerCrop</code> to <code>fitXY</code>. </p>
  
  <pre><code>android:scaleType="fitXY"
  </code></pre>
  
  <p>Now the image is scaled to the width of the screen but <strong>not</strong> scaled on the y-axis, resulting in a <strong>distorted</strong> image.</p>
  
  <p>Removing <code>android:adjustViewBounds="true"</code> has no effect. Adding an <code>android:layout_gravity</code>, as suggested elsewhere, has again no effect. </p>
  
  <p>I have tried other combinations -- to no avail. So, please does anyone know:</p>
  
  <p><strong>How do you set up the XML of an ImageView to fill the width of the screen, scale a smaller image to fill the entire view, displaying the image with its aspect ratio without distortion or cropping?</strong></p>
  
  <p>EDIT: I also tried setting an arbitrary numeric height. This only has an effect with the <code>centerCrop</code> setting. It will distort the image vertically according to the view height.</p>