title: Android RelativeLayout addrule not working while adding inflated views
body: <p>I am inflating a xml file to a custom view and adding it to a Relative Layout.</p>
  
  <p>While adding the custom views to Relative Layout i am setting some rules using the addRule method. But the views are always getting added at top left corner, am i missing something here?</p>
  
  <p>here is my code and layouts.</p>
  
  <p>MainActivity.java</p>
  
  <pre><code>public class MainActivity extends Activity {
  
          @Override
          protected void onCreate(android.os.Bundle savedInstanceState) 
          {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.mainLayout);
              RelativeLayout rl = (RelativeLayout)findViewById(R.id.relativeLayout);
  
              CustomLayout cLayout = new CustomLayout(this);
              RelativeLayout.LayoutParams lp = new  RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
              lp.addRule(RelativeLayout.BELOW, R.id.title);
              cLayout.setLayoutParams(lp);
              rl.addView(cLayout);        
          };
      }
  </code></pre>
  
  <p>CustomLayout.java</p>
  
  <pre><code>public class CustomLayout extends RelativeLayout {
  
      public CustomLayout(Context context) {
          super(context);
          LayoutInflater.from(context).inflate(R.layout.customlayout, this);
      }
  }
  </code></pre>
  
  <p>mainlayout.xml</p>
  
  <pre><code>&lt;HorizontalScrollView
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/contentScroller"
      android:layout_width="wrap_content"
      android:layout_height="match_parent"&gt;
      &lt;RelativeLayout
          android:layout_width="wrap_content"
          android:layout_height="match_parent" &gt;
  
          &lt;RelativeLayout
              android:id="@+id/mainInfo"
              android:layout_width="400dp"
              android:layout_height="match_parent" &gt;
  
              &lt;ImageView
                  android:id="@+id/mainImage"
                  android:layout_width="200dp"
                  android:layout_height="200dp"
                  android:src="@drawable/lines"/&gt;
              &lt;TextView 
                  android:id="@+id/mainDesc" 
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:layout_below="@+id/mainImage"
                  android:textColor="@android:color/white"
                  android:text="@string/desc"/&gt;
          &lt;/RelativeLayout&gt;
          &lt;RelativeLayout 
              android:id="@+id/relativeLayout"
              android:layout_height="match_parent"
              android:layout_width="match_parent"
              android:layout_toRightOf="@+id/mainInfo"&gt;
              &lt;TextView
                  android:id="@+id/title"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content" 
                  android:text="@string/titletext"/&gt;
         &lt;/RelativeLayout&gt;
      &lt;/RelativeLayout&gt;
  &lt;/HorizontalScrollView&gt;
  </code></pre>
  
  <p>customlayout.xml</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:id="@+id/background"&gt;
  &lt;ImageView
      android:id="@+id/icon"
      android:layout_width="100dp"
      android:layout_height="100dp"
      android:layout_alignParentLeft="true"
      android:layout_alignParentTop="true"
      android:layout_marginRight="10dp"
      android:scaleType="fitStart"
      android:src="@drawable/appicon" &gt;
  &lt;/ImageView&gt;
  &lt;TextView
      android:id="@+id/name"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:text="@string/sampletext"
      android:layout_toRightOf="@+id/icon"/&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>