TableLayout differences when populating programmatically
<p>I'm getting different results when creating a TableLayout from xml vs. programmatically.  In pure xml, all three children of the TableRow (which are ImageView subclasses in my test code) expand in width so they fill the table horizontally, each taking one-third the width.  But when done programmatically, they are always the minimum size they can be to hold their content.  I want them to expand, but I don't want to hard code the xml.</p>

<p>Although I also tried "pure" programmatic building of the children of the TableRow, below I show it my preferred way, where I, in a loop, inflate each of the children from an xml file that contains just that component, and then add them to the TableRow.  (note that I create the TableRow programmatically)</p>

<p>Here is main.xml.  Note that the TableRow and children are commented out here, since this is the programmatic version.  (uncomment to do it purely xml)</p>

<pre><code>&lt;view class="com.whatev.ButtonMenu"
    android:background="@drawable/test1" 
    android:layout_height="50px" android:layout_width="fill_parent" android:padding="0px"
    android:layout_alignBottom="@+id/map" android:id="@+id/buttonMenu" &gt;
&lt;!-- TableRow&gt;

    &lt;view xmlns:android="http://schemas.android.com/apk/res/android" class="com.whatev.MenuButton" 
    android:background="@drawable/test2" android:src="@drawable/bg" 
    android:scaleType="center" android:cropToPadding="false" android:padding="3px"  android:layout_weight="20"
    android:layout_height="fill_parent" android:layout_width="wrap_content" /&gt;
    &lt;view xmlns:android="http://schemas.android.com/apk/res/android" class="com.whatev.MenuButton" 
    android:background="@drawable/test2" android:src="@drawable/bg" 
    android:scaleType="center" android:cropToPadding="false" android:padding="3px"  android:layout_weight="20"
    android:layout_height="fill_parent" android:layout_width="wrap_content" /&gt;
    &lt;view xmlns:android="http://schemas.android.com/apk/res/android" class="com.whatev.MenuButton" 
    android:background="@drawable/test2" android:src="@drawable/bg" 
    android:scaleType="center" android:cropToPadding="false" android:padding="3px"  android:layout_weight="20"
    android:layout_height="fill_parent" android:layout_width="wrap_content" /&gt;
    &lt;/TableRow --&gt;
    &lt;/view&gt;
</code></pre>

<p>Then in filterbutton.xml, I have this (which is the same as the repeated stuff in comments above):</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;view xmlns:android="http://schemas.android.com/apk/res/android" class="com.whatev.MenuButton" 
    android:background="@drawable/test2" android:src="@drawable/bg" 
    android:scaleType="center" android:cropToPadding="false" android:padding="3px"  android:layout_weight="20"
    android:layout_height="fill_parent" android:layout_width="wrap_content"  /&gt;
    /&gt;
</code></pre>

<p>Finally, here is the java code for the constructor of ButtonMenu, which is a subclass of TableLayout.  (comment out everything but the call to super() to do it pure XML.)</p>

<pre><code>public ButtonMenu(Context context, AttributeSet attrs) {
        super(context, attrs);

        TableRow firstTableRow = new TableRow(context);

        for (int i=0; i&lt;3; i++) {
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            MenuButton mb = (MenuButton)inflater.inflate(R.layout.filterbutton, null);
            firstTableRow.addView(mb);
        } 
        this.addView(firstTableRow);
    }
</code></pre>

<p>Any ideas why it behaves differently, or what I have to do to get the children ("MenuButtons") to expand to each be one third the width of the TableLayout ("ButtonMenu")?  Note that in the "real" case, there will be a variable number of buttons, not always 3.</p>
