使用colspan时不遵守单元格宽度

时间:2017-01-07 13:21:50

标签: java libgdx scene2d

我试图在我的LibGDX表中设置单元格宽度,而忽略了我传递的值。我怀疑这是因为它排在满满的行并且有一些colspan,但我无法解释为什么它会发生。

这是一个屏幕: Example

我希望我的播放按钮的单元格宽度更小,所以我写了那段代码:

setDebug(true, true); //just mentionning, this is in the constructor of a class that extends Table, to prevent having table creation code on my screen

setWidth(400f);
setHeight(80f);

padLeft(30f);
padRight(30f);

Image image = new Image(assets.getTexture("gfx/menu/level-online.png")); //TODO icon depends on state
image.setScaling(Scaling.fill);

Button playButton = new TextButton(level.getType() == LevelType.RACE ? "Play" : "Visit", skin);
Button editButton = new TextButton("Edit", skin);

add(level.getName()).bottom().left().colspan(2).expand();
add(image).width(30f).height(30f);
row();
add(level.getOwner()).top().left().colspan(3).expand();
row();
add(playButton).width(40f).center(); //HERE
add(editButton).left().colspan(2); 

正如您所看到的,播放按钮的单元格宽度应该是40,但它的方式更多。 (作为参考,云是30 x 30)我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

使用我最后一行中的表来分隔元素。感谢Xoppa和Tenfour04的帮助。

add(level.getName()).bottom().left().colspan(2).expand();
add(image).width(30f).height(30f);
row();
add(level.getOwner()).top().left().colspan(3).expand();
row();
Table buttons = new Table();

buttons.add(playButton).padRight(10f);
buttons.add(editButton);

add(buttons).expand().colspan(3).left();
相关问题