2016-01-12 77 views
0

我有這樣的代碼建立了一塊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分數被推到側面和歷史標籤來獲取剩餘空間,但是這是它在做什麼:

Game UI

難道我做錯了什麼嗎?我看不出有什麼可能是錯誤的。

如果您想查看其餘的代碼,請查看github,或者只是詢問,我會提供更多的上下文。

回答

1

而不是使用一個表執行整個佈局,請嘗試嵌套表,其中每個內部表是一行。這消除了對所有colspan的需求,您可以創建列並根據需要佈置每個行表,而不會影響其他行。

+0

這就是我要與此同時,我還通過在分數標籤上使用uniform()方法,讓它像我想要的那樣工作,但使用更多的表格可以讓我更好地控制佈局。 – TheOsirian

0

如果你不希望使用更多的表在接受答案的建議,我設法得到它通過調用得分細胞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();