title: How to lay out Views in RelativeLayout programmatically?
body: <p>I'm trying to achieve the following programmatically (rather than declaratively via XML):</p>
  
  <pre><code>&lt;RelativeLayout...&gt;
     &lt;TextView ...
        android:id="@+id/label1" /&gt;
     &lt;TextView ...
        android:id="@+id/label2"
        android:layout_below: "@id/label1" /&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>In other words, how do I make the second <code>TextView</code> appear below the first one, but I want to do it in code:</p>
  
  <pre><code>RelativeLayout layout = new RelativeLayout(this);
  TextView label1 = new TextView(this);
  TextView label2 = new TextView(this);
  ...
  layout.addView(label1);
  layout.addView(label2);
  setContentView(layout);
  </code></pre>
  
  <h3>Update:</h3>
  
  <p>Thanks, TreeUK. I understand the general direction, but it still doesn't work - "B" overlaps "A". What am I doing wrong?</p>
  
  <pre><code>RelativeLayout layout = new RelativeLayout(this);
  TextView tv1 = new TextView(this);
  tv1.setText("A");
  
  TextView tv2 = new TextView(this);
  tv2.setText("B");
  RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
          RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.FILL_PARENT);
  lp.addRule(RelativeLayout.RIGHT_OF, tv1.getId());
  
  layout.addView(tv1);        
  layout.addView(tv2, lp);
  </code></pre>