title: Change ImageView size programmatically
body: <p>I have a relative layout with 3 ImageViews. The first one is a square image, the second is just used for spacing, and the third one is another square image.</p>
  
  <p>Here is the xml code for that layout:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/radioSV"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"&gt;
  
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent" 
      android:id="@+id/radioLayout"
      android:orientation="vertical"
      android:gravity="center"&gt;
  
      &lt;RelativeLayout
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent" 
          android:layout_height="wrap_content"
          android:gravity="center"&gt;
  
      &lt;ImageView
          android:id="@+id/sssImageView"
          android:src="@drawable/radio_sss_400_r"
          android:layout_width="10sp"
          android:layout_height="10sp"
          android:layout_gravity="center"
          android:scaleType="centerCrop"&gt;
      &lt;/ImageView&gt;
  
      &lt;!-- spacing --&gt;
  
      &lt;ImageView
          android:id="@+id/spacing1"
          android:background="@android:color/transparent"
          android:layout_width="wrap_content"
          android:layout_height="10dip"
          android:layout_below="@id/sssImageView"&gt;
      &lt;/ImageView&gt;
  
      &lt;ImageView
          android:id="@+id/gaImageView"
          android:src="@drawable/radio_ga_400_r"
          android:layout_width="10sp"
          android:layout_height="10sp"
          android:layout_gravity="center"
          android:scaleType="centerCrop"
          android:layout_below="@id/spacing1"&gt;
      &lt;/ImageView&gt;
  
      &lt;/RelativeLayout&gt;
  &lt;/LinearLayout&gt;
  &lt;/ScrollView&gt;
  </code></pre>
  
  <p>Now, I want my app to be useful for various screen densities, so therefore, in the java file, I ask for the density and use a switch-case statement afterwards. In this statement, the size (width, height) of the 2 ImageViews (<code>sssImageView</code> and <code>gaImageView</code>) have to be changed.</p>
  
  <p>For instance, if the density of the screen is high, I want the width and height of the ImageViews to be 200sp. I've just put 10sp in the xml as a 'standard' value.</p>
  
  <p>This is the part of the use-case statement for high screen density:</p>
  
  <pre><code>case DisplayMetrics.DENSITY_HIGH:
      layoutParams = new RelativeLayout.LayoutParams(val_high, val_high);
      sssImageView.setLayoutParams(layoutParams);
      sssImageView.setMaxHeight(val_high);
      sssImageView.setMaxWidth(val_high);
  
      gaImageView.setLayoutParams(layoutParams);
      gaImageView.setMaxHeight(val_high);
      gaImageView.setMaxWidth(val_high);
      break;
  </code></pre>
  
  <p>Also, <code>val_high</code> is 200sp:</p>
  
  <pre><code>int val_high = (int) TypedValue.applyDimension(
                  TypedValue.COMPLEX_UNIT_SP, 200, this.getResources().getDisplayMetrics());
  </code></pre>
  
  <p>Now, the part with the ImageView <code>sssImageView</code> works perfectly. It correctly enlarges the image from 10sp to 200sp (don't worry - the image is not 10sp originally!).
  The <strong>problem</strong> is the fact that the other ImageView, <code>gaImageView</code>, puts itself on top of <code>sssImageView</code> and destroys the layout. If I comment out the 3 lines with <code>gaImageView</code>, it is on its correct place in the layout, but is still small (10sp) of course.</p>
  
  <p>I have also tried the opposite: commenting out the 3 lines with <code>sssImageView</code> and only manipulating <code>gaImageView</code>. Now the top ImageView (<code>sssImageView</code>) is on its correct place and small as expected. However, the bottom ImageView, <code>gaImageView</code>, positions itself on top of <code>sssImageView</code>, and not below as written in the xml layout file.</p>
  
  <p>What is wrong here?</p>