title: Programmatically position a button in relative layout
body: <p>This is the layout XML I am using.</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:background="@color/tabTransparent"
      android:id="@+id/aLayoutRelative"&gt;
  
      &lt;LinearLayout
          android:id="@+id/linearLayout8"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_alignLeft="@+id/linearLayout7"
          android:layout_below="@+id/linearLayout7"
          android:layout_marginTop="14dp" &gt;
  
          &lt;Button
              android:id="@+id/button5"
              style="?android:attr/buttonStyleSmall"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:text="@string/text_accounts_aHistoryNotes" /&gt;
      &lt;/LinearLayout&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>I want to add the button programmatically in java source. This is what I tried.</p>
  
  <pre><code>RelativeLayout relativeLayout = (RelativeLayout)findViewById(R.id.aLayoutRelative);
  LinearLayout lastLinearLayout = (LinearLayout)findViewById(R.id.linearLayout8);
  lastLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
  
  LinearLayout linearLayout = new LinearLayout(this);
  linearLayout.setOrientation(LinearLayout.HORIZONTAL);
  LayoutParams layoutParams = new LayoutParams(LayoutParams.FILL_PARENT,       LayoutParams.WRAP_CONTENT);
  layoutParams.addRule(RelativeLayout.LEFT_OF, lastLinearLayout.getId());
  layoutParams.addRule(RelativeLayout.BELOW, lastLinearLayout.getId());
  layoutParams.setMargins(0, 14, 0, 0);
  linearLayout.setLayoutParams(layoutParams);
  
  Button button9 = new Button(this);
  Log.i("tab0", recordTabs.get(0));
  button9.setText(""+recordTabs.get(0));
  button9.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
  linearLayout.addView(button9);
  relativeLayout.addView(linearLayout);
  </code></pre>
  
  <p>But in the view, the button is vertical with no text on it; aligned towards left of the page (in effect towards relative layout). XML version works well. I reckon the orientation settings turn out to be the culprit. Having googled in various documentations hardly helped.</p>
  
  <p>Any thoughts?</p>
  
  <p>Thanks in advance!</p>