title: Dynamic number of buttons in LinearLayout
body: <p>In the <code>onCreate</code> method of my <code>Activity</code> I know the number of <code>Buttons</code> which I want in <code>col0</code>. In the following example it are four <code>Buttons</code>. Then my <code>TextView</code> <code>v0</code> gets the <code>android:layout_weight</code> set to <code>number of buttons minus one</code> (this is because <code>v1</code> should be of the same height as all the <code>Buttons</code>). Instead of providing for each possible number of buttons an own xml file it would be much nicer, if one could generalize such that dynamic java codes somehow produces the appropriate layout. How is that possible?</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:baselineAligned="false"
      android:orientation="horizontal"&gt;
  
      &lt;LinearLayout
          android:id="@+id/col0"
          android:layout_width="0dip"
          android:layout_height="match_parent"
          android:layout_weight="1"
          android:baselineAligned="false"
          android:orientation="vertical"&gt;
  
          &lt;Button
              android:id="@+id/b0"
              style="@style/MyButton" /&gt;
  
          &lt;Button
              android:id="@+id/b1"
              style="@style/MyButton" /&gt;
  
          &lt;Button
              android:id="@+id/b2"
              style="@style/MyButton" /&gt;
  
          &lt;Button
              android:id="@+id/b3"
              style="@style/MyButton" /&gt;
  
      &lt;/LinearLayout&gt;
  
      &lt;LinearLayout
          android:id="@+id/col1"
          android:layout_width="0dip"
          android:layout_height="match_parent"
          android:layout_weight="6"
          android:baselineAligned="false"
          android:orientation="vertical"&gt;
  
          &lt;TextView
              android:id="@+id/v0"
              android:layout_width="match_parent"
              android:layout_height="0dip"
              android:layout_weight="3" /&gt;
  
          &lt;TextView
              android:id="@+id/v1"
              android:layout_width="match_parent"
              android:layout_height="0dip"
              android:layout_weight="1" /&gt;
  
      &lt;/LinearLayout&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>