我想创建一个动态添加按钮的布局。在此,要添加的按钮数量取决于运行时,即取决于服务器返回的按钮数量,我想添加按钮。
for (int k = 1; k < 100; k++) {
TableRow row = new TableRow(this);
innerloop:
for (int l = 1; l <4; l++) {
btn = new Button(this);
TableRow.LayoutParams tr= new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
layout.setWeightSum(12.0f);
tr.weight=0;
btn.setLayoutParams(tr);
btn.setTextColor(a);
// btn.setLayoutParams(params);
btn.setHeight(150);
// Log.v("y", "how much"+size.x+" "+size.y);
btn.setWidth(150);
btn.setId(idb);
btn.setOnClickListener(this);
btn.setText("Button " + idb);
// Log.v("idb", "created"+" "+btn.getId());
row.addView(btn);
}
}