Android TableLayout中按钮的背景色
我很难弄清楚为什么会这样:Android TableLayout中按钮的背景色,android,Android,我很难弄清楚为什么会这样: TableLayout table = (TableLayout) this.findViewById(R.id.tablelayout); int counter = 1; for (int i = 0; i < nrows; i++) { TableRow row = new TableRow(this); table.addView(row); for (int j = 0; j &l
TableLayout table = (TableLayout) this.findViewById(R.id.tablelayout);
int counter = 1;
for (int i = 0; i < nrows; i++) {
TableRow row = new TableRow(this);
table.addView(row);
for (int j = 0; j < ncols; j++) {
FrameLayout cell = new FrameLayout(this);
cell.setBackgroundColor((i + j) % 2 == 0 ? Color.YELLOW : Color.WHITE);
Button b = new Button(this, null, android.R.attr.buttonStyleSmall);
b.setTextSize(TypedValue.COMPLEX_UNIT_DIP,10);
b.setText("B-\n" + Integer.toString(counter++));
b.setPadding(0,0,0,0);
b.setLayoutParams(new FrameLayout.LayoutParams(120, 120, 0x11));
// 0x11 = center
if (i == 3 && j == 3)
b.setBackground(new ColorDrawable(0xcc0088));
cell.addView(b);
row.addView(cell);
cell.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.MATCH_PARENT, 1F));
}
row.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0, 1F));
}
TableLayout table=(TableLayout)this.findviewbyd(R.id.TableLayout);
int计数器=1;
对于(int i=0;i
我使用的是nrows==10
,ncols==5
。这将显示一个由白色和黄色“方块”组成的棋盘格图案,除(3,3)之外的每个方块的中心是一个灰色按钮,其中包含一些文本。不过,在(3,3)正方形中,我使用了带有一种洋红色的彩色可绘制的设置背景,只有文本出现;除文字外,正方形全是黄色。没有灰色按钮,但我尝试应用于按钮的洋红色也没有显示在任何地方。(使用b.setBackgroundColor(0xcc0088)
具有相同的结果。)
对发生的事情有什么解释吗?我是否遗漏了一些明显的东西,或者表格布局中的按钮是否有不同的行为,或者是什么?如何以编程方式设置按钮的颜色,而不更改封闭正方形的颜色?(0xcc0088)的alpha为0,这是您想要的吗?我不认为so@pskink呜呜呜呜呜呜。。。谢谢我希望这是件简单的事。