【发布时间】:2016-02-21 06:35:56
【问题描述】:
我通过代码将 7x7 按钮集添加到表格 TableLayout 中,在我想为按钮设置背景颜色之前一切都很好。 enter image description here
在我设置背景颜色后,按钮变得比以前大了..
这是我的代码
private void initGameBoard(){
mTableLayout= (TableLayout) findViewById(R.id.table_layout);
int counter = 1;
for(int row=0;row<7;row++) {
TableRow tableRow=new TableRow(this);
for(int col=0;col<7;col++) {
mTableLayout.setColumnShrinkable(col, true);
Button button=new Button(this);
button.setTag(counter);
if (counter == 2){
button.setBackgroundColor(Color.YELLOW);
}
tableRow.addView(button);
counter++;
}
mTableLayout.addView(tableRow, new LayoutParams(FP, WC));
}
}
【问题讨论】:
标签: android android-tablelayout