参考别人写的一个代码 main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/tableLayout1"> </TableLayout> </LinearLayout> TableRowTest package Android_zjk.TableRowTest; import android.app.Activity; import android.os.Bundle; import android.view.ViewGroup; import android.widget.TableLayout; import android.widget.TableRow; import android.widget.TextView; public class TableRowTest extends Activity { /** Called when the activity is first created. */ private final int WC = ViewGroup.LayoutParams.WRAP_CONTENT; private final int FP = ViewGroup.LayoutParams.FILL_PARENT; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //新建TableLayout01的实例 TableLayout tableLayout = (TableLayout)findViewById(R.id.tableLayout1); //全部列自动填充空白处 tableLayout.setStretchAllColumns(true); for(int row = 0; row < 10 ; row++) { TableRow tableRow = new TableRow(this); for(int col = 0 ; col < 10; col++) { //tv用于显示 TextView tv=new TextView(this); tv.setText("("+col+","+row+")"); tableRow.addView(tv); } //新建的TableRow添加到TableLayout tableLayout.addView(tableRow, new TableLayout.LayoutParams(FP, WC)); } } } 运行结果