0

我正在以编程方式在屏幕上生成按钮这是我的代码

       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 或更多后才会出现此问题。

4

1 回答 1

0

我能够在我的模拟器上看到第 6 行。我猜电话宽度是问题所在

于 2013-05-13T10:16:23.050 回答