【发布时间】:2015-04-24 21:55:34
【问题描述】:
我想根据需要创建许多具有恒定宽度和高度的按钮。
如何在android中进行以下操作?
for(row =0; row*buttonSizeY<otherButtonYCoardinate;row++){
addButtonsToRow();
}
do{
row++;
addButtonsToRow();
}while(stillNeedToAddButton);
void addButtonsToRow(){
for(col=0;col*buttonSizeX<screenWidth;col++){
//instantiate button and set its X,Y coords according to row and col
relativeLayer.add(button);
}
}
我没有找到一种真正的方法来按需添加带有按钮的布局。我想在上面使用 TableLayout 并将 LinearLayouts 添加到其中,只要我有空间给它们,但是我没有找到一种方法来包含而不在 XML 中指定所有 LinearLayout-s。我的屏幕宽度间距也有问题:我的按钮具有恒定的高度和宽度,因为它是椭圆形的。所以我不能使用 layout_weight。
【问题讨论】:
标签: android android-layout android-button android-layout-weight