【问题标题】:Unable to display all the buttons in TableLayout无法显示 TableLayout 中的所有按钮
【发布时间】: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


【解决方案1】:

我能够在模拟器上看到第 6 行。我猜是手机宽度问题

【讨论】:

    猜你喜欢
    • 2017-01-18
    • 1970-01-01
    • 2022-09-22
    • 1970-01-01
    • 1970-01-01
    • 2014-04-18
    • 1970-01-01
    • 2021-05-28
    • 1970-01-01
    相关资源
    最近更新 更多