title: How to dynamically change ImageView Height
body: <p>I have a simple linear layout used for ListView's cell, and it has an imageview. The image will be downloaded from internet, so the size can be different sizes.</p>
  
  <p>However, I want to set the width of imageview to be fill_parent, which is fixed, and dynamically change the image height at runtime.  Rules to set the image height: 
  if the image's h/w ratio is more than 1, make the ImageView square, means match the height to the width.</p>
  
  <p>if the image's h/w ratio is less than 1, size it proportionally. Expected two samples as below.</p>
  
  <p>The First one is h/w&lt;1, while the second one 'Cat' is h/w>1.</p>
  
  <p><img src="https://i.stack.imgur.com/d14xc.png" alt="enter image description here">
  <img src="https://i.stack.imgur.com/Pp6Ld.png" alt="enter image description here">
  Thanks for your time.  </p>
  
  <pre><code>    &lt;LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:background="@color/white"
      android:orientation="vertical"
      android:padding="10dp" &gt;
  
          &lt;TextView
          android:id="@+id/postTitle"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:ellipsize="end"
          android:maxLines="2"
          android:textColor="@color/black"
          android:textSize="18sp"
          android:textStyle="bold" /&gt;
  
         &lt;ImageView
          android:id="@+id/postImg"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_marginTop="10dp"
          android:scaleType="centerCrop"
          android:src="@drawable/dummy_image"
          android:contentDescription="@string/postImage"  /&gt;
     &lt;/LinearLayout&gt;
  </code></pre>