如何以编程方式将此表格布局设置为 Android 具有相等的列宽?

How can I programmatically set this tablelayout to have equal column widths for Android?

我正在尝试以编程方式在 table 标题下方创建行,但它们溢出了,我不确定如何将它们拆分为只占宽度的 25%?

下面是创建行的代码:

TableRow row = new TableRow(activity);
lp = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.MATCH_PARENT, 1.0f);
tl = new TableLayout.LayoutParams();

tl.weight = 1;
lp.height = 100;

row.setLayoutParams(lp);
row.setWeightSum(4);


tv = new TextView(getActivity());
tv.setLayoutParams(tl);
tv.setTextSize(14);
tv.setText(whotos.get(i));

tv2 = new TextView(getActivity());
tv2.setLayoutParams(tl);
tv2.setTextSize(14);
tv2.setText(documents.get(i));

tv3 = new TextView(getActivity());
tv3.setLayoutParams(tl);
tv3.setTextSize(14);
tv3.setText(directions.get(i));

tv4 = new TextView(getActivity());
tv4.setLayoutParams(tl);
tv4.setTextSize(14);
tv4.setText(thedates.get(i));


 row.addView(tv);  //tp name
row.addView(tv2); //document type
row.addView(tv3); //direction
row.addView(tv4); //date

ll.addView(row, i + 1 + tableHeadingRows);

这是我在以编程方式创建的行上方的布局代码:

<TableRow
            android:id="@+id/tableRow2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:padding="5dip"
            android:stretchColumns="1"
            android:weightSum="4">

            <TextView
                android:id="@+id/tp"
                android:layout_weight="1"
                android:layout_width="0dp"
                android:text="TP"
                android:textAppearance="?android:attr/textAppearanceLarge" />
            <TextView
                android:id="@+id/doc"
                android:layout_weight="1"
                android:layout_width="0dp"
                android:text="Doc"
                android:textAppearance="?android:attr/textAppearanceLarge" />
            <TextView
                android:id="@+id/dir"
                android:layout_weight="1"
                android:layout_width="0dp"
                android:text="Direction"
                android:textAppearance="?android:attr/textAppearanceLarge" />
            <TextView
                android:id="@+id/date"
                android:layout_weight="1"
                android:layout_width="0dp"
                android:text="Date"
                android:textAppearance="?android:attr/textAppearanceLarge" />
        </TableRow>

        <!-- draw a red line -->
        <View
            android:layout_height="2dip"
            android:background="@color/tableHorizontalRule" />

有人能解决这个问题吗?

我将其更改为 LinearLayout,因为它简化了一些事情并允许我以编程方式轻松设置列权重。