【发布时间】:2013-05-13 18:16:23
【问题描述】:
我正在以编程方式在屏幕上生成按钮 这是我的代码
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 或更多后才会出现此问题。
【问题讨论】:
-
您是否记录了我们计算的宽度和按钮的实际宽度?听起来宽度比应有的要高。
-
不,我没有。我不知道如何使用日志
-
看看文档:developer.android.com/reference/android/util/Log.html 这样使用日志:Log.w("WIDGET","Enable is called");
-
gridSize 是一个常数。是6
-
你从哪里得到这个 gridSize?我在上面发布的代码中找不到它...
标签: android android-view android-button android-tablelayout