title: Programmatic RelativeLayout overlapping
body: <p>I have got a problem by implementing relative layout from code.
  What I want, that TextView1 is located to the left, and TextView2 to the right of the screen at one line.</p>
  
  <p>It works fine from XML, but doing this from code do not... what could be the reason?</p>
  
  <p>This work just fine:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context=".MainActivity" &gt;
  
      &lt;TextView
          android:id="@+id/textView2"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:text="@string/hello_world" /&gt;
  
      &lt;TextView
          android:id="@+id/textView1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentRight="true"
          android:text="TextView" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>This doesn't work(giving an overlapping of elements):</p>
  
  <pre><code>RelativeLayout rel = new RelativeLayout(this);
  RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,
          LayoutParams.WRAP_CONTENT);
  rel.setLayoutParams(params);
  
  TextView t1 = new TextView(this);   
  t1.setText("balbla_1");
  RelativeLayout.LayoutParams lp1 = new RelativeLayout.LayoutParams(
          RelativeLayout.LayoutParams.MATCH_PARENT,
          RelativeLayout.LayoutParams.WRAP_CONTENT);
  lp1.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
  t1.setLayoutParams(lp1);
  
  TextView t2 = new TextView(this);
  t2.setText("balbla_2");
  RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(
          RelativeLayout.LayoutParams.MATCH_PARENT,
          RelativeLayout.LayoutParams.WRAP_CONTENT);
  lp2.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
  t2.setLayoutParams(lp2);        
  
  rel.addView(t1);
  rel.addView(t2);
  
  setContentView(rel);
  </code></pre>
  
  <p>but this would work fine: (replace <code>MATCH_PARENT</code> with <code>WRAP_CONTENT</code>):</p>
  
  <pre><code>RelativeLayout rel = new RelativeLayout(this);
  RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,
          LayoutParams.WRAP_CONTENT);
  rel.setLayoutParams(params);
  
  TextView t1 = new TextView(this);   
  t1.setText("balbla_1");
  RelativeLayout.LayoutParams lp1 = new RelativeLayout.LayoutParams(
          RelativeLayout.LayoutParams.WRAP_CONTENT,
          RelativeLayout.LayoutParams.WRAP_CONTENT);
  lp1.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
  t1.setLayoutParams(lp1);
  
  TextView t2 = new TextView(this);
  t2.setText("balbla_2");
  RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(
          RelativeLayout.LayoutParams.WRAP_CONTENT,
          RelativeLayout.LayoutParams.WRAP_CONTENT);
  lp2.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
  t2.setLayoutParams(lp2);        
  
  rel.addView(t1);
  rel.addView(t2);
  
  setContentView(rel);
  </code></pre>