LinearLayout ll=new LinearLayout(thisContext);
for(int i=0;i<10;i++)
{
Button b=new Button(thisContext);
b.setText("Button"+i);
b.setBackgroundColor(Color.GREEN);
ll.addview(b);
}
答案 0 :(得分:1)
// try this way,hope this will help you...
LinearLayout ll=new LinearLayout(thisContext);
for(int i=0;i<10;i++)
{
Button b=new Button(thisContext);
LinearLayout.LayoutParams bParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
bParams.setMargins(5,5,5,5);
b.setLayoutParams(bParams);
b.setText("Button"+i);
b.setBackgroundColor(Color.GREEN);
ll.addview(b);
}