我正在以编程方式在屏幕上生成按钮这是我的代码
TableLayout MainLayout = new TableLayout(this);
MainLayout.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.MATCH_PARENT));
//MainLayout.setStretchAllColumns(true);
for ( int i =0 ; i < gridSize ; i++){
rowArr[i] = new TableRow(this);
for(int j = 0; j < gridSize ; j++){
Button button = new Button(this);
button.setText(Integer.toString(i)+","+Integer.toString(j));
button.setTextSize(150/gridSize);
button.setMaxHeight(450/gridSize);
button.setMaxWidth(600/gridSize);
rowArr[i].addView(button);
}
MainLayout.addView(rowArr[i]);
}
通过查看图像,您可以缺少一整列按钮。
只有在将我的 gridSize 设置为 6 或更多后才会出现此问题。