如果您想以编程方式添加它们,您可以在垂直线性布局中使用水平线性布局来保留您的按钮。
这是一个示例代码:
LinearLayout InitQuiteSomeButtons(Button[] butts,int buttonsPerRow)
{
LinearLayout vlay = new LinearLayout(this);
LinearLayout.LayoutParams vParams= new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
vlay.setLayoutParams(vParams);
vlay.setOrientation(LinearLayout.VERTICAL);
LinearLayout hLay=new LinearLayout(this);
LinearLayout.LayoutParams hParams= new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
hLay.setLayoutParams(hParams);
hLay.setOrientation(LinearLayout.HORIZONTAL);
for (int i=0;i<butts.length;i++)
{
if (i>0 && i%buttonsPerRow==0)
{
vlay.addView(hLay);
hLay = new LinearLayout(this);
hLay.setLayoutParams(hParams);
hLay.setOrientation(LinearLayout.HORIZONTAL);
}
hLay.addView(butts[i]);
}
if (butts.length%buttonsPerRow==0)
{
//add the non-filledrow
vLay.addView(hLay);
}
return vlay;
}