title: Android ImageView adjusting parent's height and fitting width
body: <p><strong>Update</strong> : I solved this issue by using the method described in <a href="https://stackoverflow.com/questions/2991110/android-how-to-stretch-an-image-to-the-screen-width-while-maintaining-aspect-rat">this answer</a></p>
  
  <p>I'm a bit stuck with this issue, which I think should be pretty simple.</p>
  
  <p>So my app downloads an image, and renders the bitmap in an ImageView, a child element of a RelativeLayout.
  I would like the ImageView to fit the parent width, and to adapt it's size to keep the aspect ratio.</p>
  
  <p>Here is my XML :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  &gt;
  &lt;RelativeLayout android:id="@+id/banner" android:layout_width="fill_parent" android:layout_height="wrap_content"&gt;&lt;/RelativeLayout&gt;
  &lt;TextView  
  android:layout_width="fill_parent" 
  android:layout_height="wrap_content" 
  android:text="@string/hello"
  /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>And the code :</p>
  
  <pre><code>public void onCreate(Bundle savedInstanceState) {
  
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
  
      RelativeLayout banner = (RelativeLayout) findViewById(R.id.banner);
      ImageView imgV = new ImageView(this);
  
      imgV.setScaleType(ImageView.ScaleType.CENTER_CROP);
      // I tried all the scale types : CENTER_INSIDE : same effect, FIT_CENTER : same effect... 
  
      imgV.setBackgroundColor(0x00FFFF00);
  
      imgV.setAdjustViewBounds(Color.BLUE);
  
  
      RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
  
      banner.addView(imgV,params);
  
      // Some code downloading the image stream
  
      bitmap = BitmapFactory.decodeStream(stream);
  
  
      imgV.setImageBitmap(bitmap);
  
      }
  </code></pre>
  
  <p><strong>Desired :</strong></p>
  
  <p><img src="https://i.stack.imgur.com/OYj5n.jpg" alt="Desired result"></p>
  
  <p><strong>Result :</strong></p>
  
  <p><img src="https://i.stack.imgur.com/ewIjL.jpg" alt="Current result"></p>