Reputation: 298
I have this code building a piece of 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();
I expected it to make the player and cpu scores get pushed to the sides and the history label to get the remaining space, but this is what it's doing:
Am I doing something wrong here? I can't see what could be the error.
If you want to take a look on the rest of the code, it's on github, or just ask and I'll provide more context.
Upvotes: 0
Views: 71
Reputation: 298
If you don't want to use more tables as suggested in the accepted answer, I managed to get it working by calling uniform() in the score cells, like so:
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();
Upvotes: 0
Reputation: 1517
Instead of doing the entire layout with one table, try nesting tables where each inner table is a row. This eliminates the need for colspan all together and you can create columns and lay out each row table however you want without affecting the other rows.
Upvotes: 1