How can I stretch a programmatically created tablelayout with fragments?
<p>I know this question has been asked in different forms, but I cannot get an Android TableLayout to stretch vertically. I have a main layout which inserts a fragment into each cell of a tablelayout. When I run the code, the tablelayout stretches horizontally, but not vertically.</p>

<p><strong>The Main UI is:</strong></p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"&gt;
&lt;ImageButton
        android:id="@+id/btnLeft"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:background="@drawable/leftarrow"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        /&gt;
&lt;TextView
        android:id="@+id/tvMonthYear"
        android:layout_width="wrap_content"
        android:layout_height="30dp"
        android:text="January 2013"
        android:layout_toRightOf="@+id/btnLeft"
        android:layout_alignParentTop="true"
        android:textSize="18sp"
        /&gt;
&lt;ImageButton
        android:id="@+id/btnRight"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:background="@drawable/rightarrow"
        android:layout_toRightOf="@+id/tvMonthYear"
        android:layout_alignParentTop="true"
        /&gt;
&lt;ImageButton
        android:id="@+id/btnInsert"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:background="@drawable/plus"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        /&gt;
&lt;TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_width="fill_parent"
             android:layout_height="fill_parent"
             android:layout_alignParentLeft="true"
             android:layout_below="@+id/btnLeft"
             android:id="@+id/tlCalendar"
             android:stretchColumns="*"
         &gt;
        &lt;/TableLayout&gt;
</code></pre>

<p></p>

<p><strong>The Activity class is:</strong></p>

<pre><code>package com.example;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.FrameLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import java.util.Date;

public class CalendarActivity extends Activity
{
    private final int BASE_CONTENT_VIEW_ID = 10101010;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.calendar);

        DrawCalendar(new Date(), savedInstanceState);
}

private void DrawCalendar(Date d, Bundle savedInstanceState)
{
    final int rows = 6;
    final int cols = 7;

    if (savedInstanceState != null)
        return;

    TableLayout table = (TableLayout) findViewById(R.id.tlCalendar);

    TableRow.LayoutParams rowLp = new TableRow.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT,
            1.0f);

    for (int i=0; i&lt;rows; i++)
    {
        TableRow row = new TableRow(this);

        for(int j=0; j&lt;cols; j++)
        {
            int id = BASE_CONTENT_VIEW_ID + i * cols + j;
            FrameLayout frameLayout = new FrameLayout(this);          //holder for fragment
            frameLayout.setId(id);
            FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(
                    ViewGroup.LayoutParams.FILL_PARENT,
                    ViewGroup.LayoutParams.FILL_PARENT);
            frameLayout.setLayoutParams(lp);

            Fragment calendarCellFragment = new CalendarCellFragment();
            FragmentManager fragmentManager = getFragmentManager();
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            fragmentTransaction.add(id, calendarCellFragment);
            fragmentTransaction.commit();

            //add fragment
            row.addView(frameLayout, rowLp);
        }
        table.addView(row, rowLp);
    }
    //table.setStretchAllColumns(true);
}
</code></pre>

<p>}</p>

<p><strong>The fragment UI is:</strong></p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;

&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:background="@drawable/cell_shape" android:clickable="true"
          android:orientation="vertical"&gt;
&lt;TextView android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:id="@+id/tvLine1" android:text="1" android:inputType="number"/&gt;
&lt;TextView android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:id="@+id/tvLine2" android:text="Line 2"/&gt;
&lt;TextView android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:id="@+id/tvLine3" android:text="Line 3"/&gt;
&lt;/LinearLayout&gt;
</code></pre>

<p><strong>The fragment class is:</strong></p>

<pre><code>package com.example;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class CalendarCellFragment extends Fragment {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        return inflater.inflate(R.layout.calendarcell, container, false);
    }
}
</code></pre>

<p><strong>Thank you in advance!</strong></p>
