title: Dynamically created ImageView not respecting RelativeLayout rules
body: <p>I'm adding <code>ImageViews</code> dynamically to a <code>RelativeLayout</code>. I'm trying to align each image to the right of the last image. The initial image aligns correctly but when I set the next image to align to the right side of the last image, it displays at the top left of the screen, disregarding the alignment rules. </p>
  
  <p>Hierarchy <code>View</code> in the Android Device Monitor is indicating that the IDs are correctly getting set and the ImageView is recognizing that it's supposed to align to the id of the last ImageView.</p>
  
  <pre><code>    List&lt;String&gt; image_urls = rally.getTransportationImgs();
      List&lt;String&gt; methods = rally.getTransportationStrs();
      ArrayList&lt;ImageView&gt; IMGS = new ArrayList&lt;ImageView&gt;();
  
      for(int i = 0; i &lt; methods.size(); i++) {
  
          String method = methods.get(i);
  
          for(int j = 0; j &lt; image_urls.size(); j++) {
  
              String img_url = image_urls.get(j);
  
              if(img_url.toLowerCase().contains(method.toLowerCase()) == true) {
                  ImageView methodImage = new ImageView(this);
  
                  methodImage.setId(j + 100);
  
                  IMGS.add(methodImage);
  
                  RelativeLayout detailsLayout = (RelativeLayout) findViewById(R.id.details_layout);
                  TextView transportationText = (TextView) detailsLayout.findViewById(R.id.transportationText);
                  RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
  
                  if (IMGS.size() &gt; 1) {
  
                      params.addRule(RelativeLayout.RIGHT_OF, IMGS.get(IMGS.size() - 1).getId());
                      params.addRule(RelativeLayout.ALIGN_TOP, IMGS.get(IMGS.size() - 1).getId());
                      params.addRule(RelativeLayout.END_OF, IMGS.get(IMGS.size() - 1).getId());
  
                      params.height = 5000;
                      params.width = 65;
                  } else {
  
                      params.addRule(RelativeLayout.RIGHT_OF, transportationText.getId());
                      params.addRule(RelativeLayout.ALIGN_TOP, transportationText.getId());
                      params.addRule(RelativeLayout.END_OF, transportationText.getId());
  
                      params.height = 65;
                      params.width = 65;
                  }
  
  
                  methodImage.setLayoutParams(params);
  
                  detailsLayout.addView(methodImage);
  
                  Picasso.with(getApplicationContext()).load(img_url).fit().centerCrop().placeholder(R.drawable.ic_launcher).into(methodImage);
              }
          }
      }
  </code></pre>
  
  <p><strong>XML file</strong></p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:paddingLeft="0dp"
  android:paddingRight="0dp"
  android:orientation="vertical"
  android:weightSum="1"
  android:id="@+id/details_layout"&gt;
  
  &lt;ImageView
      android:layout_width="match_parent"
      android:layout_height="275dp"
      android:id="@+id/image" /&gt;
  
      &lt;TextView
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceLarge"
          android:text="Large Text"
          android:id="@+id/name2"
          android:layout_below="@id/image"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true" /&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceMedium"
          android:text="Medium Text"
          android:id="@+id/date2"
          android:layout_below="@id/name2"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true"
          android:layout_marginTop="10dp" /&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceMedium"
          android:text="Medium Text"
          android:id="@+id/creator_name2"
          android:layout_below="@id/date2"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true"
          android:layout_marginTop="10dp" /&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceMedium"
          android:text="Medium Text"
          android:id="@+id/venues"
          android:layout_below="@id/creator_name2"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true"
          android:layout_marginTop="10dp" /&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceMedium"
          android:text="Medium Text"
          android:id="@+id/transportationText"
          android:layout_below="@id/venues"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true"
          android:layout_marginTop="10dp" /&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceMedium"
          android:text="Medium Text"
          android:id="@+id/categories"
          android:layout_below="@id/transportationText"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true"
          android:layout_marginTop="10dp" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>For debugging purposes, I set the image height obnoxiously large. The gray is part of an image that is supposed to go to the right side of the ImageView that correctly aligns next to "Transportation:"</p>
  
  <p><a href="https://i.stack.imgur.com/WPjn5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WPjn5.png" alt="OUTPUT"></a></p>