簡體   English   中英

表格布局不符合預期

[英]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得分上升到兩邊,並且歷史標簽可以得到剩余的空間,但這就是它的作用:

游戲界面

我在這里做錯什么了嗎? 我看不出是什么錯誤。

如果您想看一下其余的代碼,則在github上 ,或者問一下,我將提供更多的上下文。

而不是使用一個表進行整個布局,請嘗試在每個內部表都是一行的情況下嵌套表。 這消除了全部合並的需要,並且您可以創建列並按需要布置每個行表,而不影響其他行。

如果您不想按照接受的答案中的建議使用更多表格,我設法通過在得分單元格中調用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();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM