【问题标题】:Cell width not respected when using colspan使用 colspan 时不考虑单元格宽度
【发布时间】:2017-01-07 13:21:49
【问题描述】:

我正在尝试在我的 LibGDX 表格中设置单元格宽度,但它忽略了我传递的值。我怀疑这是因为它在填充的行下方并且具有 colspan 但我无法确切解释为什么会发生这种情况。

这是一个屏幕:

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

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)我该如何解决这个问题?

【问题讨论】:

  • 尝试将expand() 添加到编辑按钮的单元格中。
  • @Tenfour04,Xoppa 在 freenode 的 #libgdx 上告诉我同样的事情。它正在工作,但正在将播放按钮拉伸到它的单元格大小。我用嵌套表修复了它。

标签: java libgdx scene2d


【解决方案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();

【讨论】:

    猜你喜欢
    • 2014-11-30
    • 2022-10-17
    • 2017-05-26
    • 1970-01-01
    • 2016-07-03
    • 2013-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多