实现效果图:

=========================================================================
- // 利用代码设置 表格布局 private void setTableLayout(){
- TableLayout tlayout = new TableLayout(this); tlayout.setColumnStretchable(2, true); // 拉长索引从0开始的第2列
- TableLayout.LayoutParams tl_lpara = new TableLayout.LayoutParams(MP,WC); // 1. TableRow 不需要设置 layout_width, layout_height
- // 2. TableRow 中的控件不能设置 layout_span 属性 TableRow tr1 = new TableRow(this);
- TextView textView0 = new TextView(this); textView0.setText("第0列");
- tr1.addView(textView0); TextView textView1 = new TextView(this);
- textView1.setText("第1列"); tr1.addView(textView1);
- TextView textView2 = new TextView(this); textView2.setText("第2列");
- textView2.setBackgroundColor(Color.CYAN); tr1.addView(textView2);
- tlayout.addView(tr1, tl_lpara); TableRow tr2 = new TableRow(this);
- Button btn0 = new Button(this); btn0.setText("按钮0");
- tr2.addView(btn0); Button btn1 = new Button(this);
- btn1.setText("按钮1"); tr2.addView(btn1);
- Button btn2 = new Button(this); btn2.setText("按钮2");
- tr2.addView(btn2); Button btn3 = new Button(this);
- btn3.setText("按钮3"); tr2.addView(btn3);
- tlayout.addView(tr2, tl_lpara); setContentView(tlayout);
- }










