Table 布局未按预期运行

Table layout is not behaving as expected

我用这段代码构建了一块 UI:

    // Trying to fix the layout by setting the defaults for the next row.
    layout.row().expand(false, false).fill(false).colspan(4);

    Label playerLabel = new Label(Settings.playerName + "  " + playerScore, skin, "defaultWhite");
    layout.add(playerLabel).colspan(1);

    Label historyLabel = new Label(getHistory(), skin, "defaultWhite");
    historyLabel.setAlignment(2);
    layout.add(historyLabel).colspan(2).expandX();

    Label cpuLabel = new Label(cpuScore + "  CPU", skin, "defaultWhite");
    layout.add(cpuLabel).colspan(1);

    layout.row();

我希望它能让玩家和 cpu 分数被推到一边,历史标签得到剩余的 space,但这就是它正在做的:

我是不是做错了什么?我看不出可能是什么错误。

如果您想查看其余代码,请访问 github,或者直接提问,我会提供更多上下文。

与其使用一个 table 来完成整个布局,不如尝试嵌套 table,其中每个内部 table 是一行。这消除了对 colspan 的需要,您可以创建列并根据需要对每一行进行布局 table,而不会影响其他行。

如果您不想按照已接受的答案中的建议使用更多表格,我设法通过在评分单元格中调用 uniform() 使其正常工作,如下所示:

layout.row().expand(false, false).fill(false).colspan(4);

Label playerLabel = new Label(Settings.playerName + "  " + playerScore, skin, "defaultWhite");
layout.add(playerLabel).colspan(1).uniform();

Label historyLabel = new Label(getHistory(), skin, "defaultWhite");
historyLabel.setAlignment(2);
layout.add(historyLabel).colspan(2).expandX();

Label cpuLabel = new Label(cpuScore + "  CPU", skin, "defaultWhite");
layout.add(cpuLabel).colspan(1).uniform();

layout.row();