[英]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.