Android layout 如何在android的代码中动态设置布局跨度、布局边距
如何在android中的代码中动态设置layout_span,layout_margin您可以使用Android layout 如何在android的代码中动态设置布局跨度、布局边距,android-layout,Android Layout,如何在android中的代码中动态设置layout_span,layout_margin您可以使用TableRow.LayoutParams实例设置layout_margin,该实例提供给TableRow.addView(): 您可以使用给定给TableRow.addView()的TableRow.LayoutParams实例设置版面边距: 这个问题在这里简单地解决了:这个问题在这里简单地解决了: TableLayout newTable = new TableLayout(DisplayCon
TableRow.LayoutParams
实例设置layout_margin,该实例提供给TableRow.addView()
:
您可以使用给定给
TableRow.addView()
的TableRow.LayoutParams
实例设置版面边距:
这个问题在这里简单地解决了:这个问题在这里简单地解决了:
TableLayout newTable = new TableLayout(DisplayContext);
int rowIndex = 0;
// First Row (3 buttons)
TableRow newRow1 = new TableRow(DisplayContext);
newRow1.addView(new Button(DisplayContext), 0);
newRow1.addView(new Button(DisplayContext), 1);
newRow1.addView(new Button(DisplayContext), 2);
newTable.addView(newRow1, rowIndex++);
// Second Row (2 buttons, last one spans 2 columns)
TableRow newRow2 = new TableRow(DisplayContext);
newRow2.addView(new Button(DisplayContext), 0);
Button newButton = new Button(DisplayContext);
// Create the layout to span two columns
TableRow.LayoutParams params = new TableRow.LayoutParams();
params.span = 2;
newRow2.addView(newButton, 1, params);
newTable.addView(newRow2, rowIndex++);