我会创建一个 TableLayout 并将其内容居中。我写了这段代码:
TableLayout tl = new TableLayout(this);
tl.setGravity(Gravity.CENTER);
TableRow firstRow = new TableRow(this);
TableRow secondRow = new TableRow(this);
但它不起作用。行居中但仅垂直...我该怎么办?
提前致谢。
编辑:
TableLayout tl = new TableLayout(this);
tl.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, Gravity.CENTER_HORIZONTAL));
TableRow firstRow = new TableRow(this);
TableRow secondRow = new TableRow(this);
firstRow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.FILL_PARENT, Gravity.CENTER));
secondRow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.FILL_PARENT, Gravity.CENTER));