我想把我的数字按钮那样。这是我的代码:
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
LinearLayout layout2 = new LinearLayout(this);
layout2.setOrientation(LinearLayout.HORIZONTAL);
TextView titleView = new TextView(this);
titleView.setText("Hello World!");
layout.addView(titleView);
android.widget.LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT, 1);
android.widget.TableLayout.LayoutParams params = new TableLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.FILL_PARENT, 1);
Button btnConnect = new Button(this);
btnConnect.setText("Connect");
btnConnect.setLayoutParams(param);
layout2.addView(btnConnect);
Button btnDisconnect = new Button(this);
btnDisconnect.setText("Disconnect");
layout2.addView(btnDisconnect);
btnDisconnect.setLayoutParams(param);
layout.addView(layout2);
TableLayout tblLayout = new TableLayout(this);
tblLayout.setOrientation(TableLayout.HORIZONTAL);
TableRow tblrow = null;
for (int i = 1; i <= 9; i++) {
if (i % 3 == 1) {
tblrow = new TableRow(this);
tblLayout.addView(tblrow);
}
Button b = new Button(this);
b.setText("" + i);
tblrow.addView(b);
}
TableRow tr = new TableRow(this);
Button btnZero = new Button(this);
btnZero.setText("0");
Button btnHash = new Button(this);
btnHash.setText("#");
Button btnStar = new Button(this);
btnStar.setText("*");
tr.addView(btnZero);
tr.addView(btnHash);
tr.addView(btnStar);
tblLayout.addView(tr);
layout.addView(tblLayout);
setContentView(layout);
这符合:
为了让我的专栏像那样。我使用了这段代码:
android.widget.TableLayout.LayoutParams params = new TableLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.FILL_PARENT, 1);
tblLayout.setLayoutParams(param);
但没有任何变化。我需要做什么?Layoutparams 还不足以做到这一点吗?