我用按钮创建了 3x3 表。
for (int i = 0, lenI = field.length; i < lenI; i++) {
TableRow row = new TableRow(this);
row.setWeightSum(1);
for (int j = 0, lenJ = field[i].length; j < lenJ; j++) {
Button button = new Button(this);
buttons[i][j] = button;
button.setOnClickListener(new Listener(i, j));
row.addView(button, new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.MATCH_PARENT));
button.layout(Gravity.CENTER, Gravity.CENTER, Gravity.CENTER, Gravity.CENTER);
}
layout.addView(row, new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT,
TableLayout.LayoutParams.MATCH_PARENT));
}
如何将它们放置在屏幕中央并设置屏幕 1/3 的宽度?现在按钮位于活动的左侧。