1 Table 个单元格与 LibGDX 中下方多个其他单元格的宽度相同

1 Table Cell with Same Width as Multiple Others Beneath It in LibGDX

我只是在寻找我在使用 LibGDX 时遇到的问题的明确答案。我一直在 LibGDX 开发 Android 游戏,遇到了创建 UI 布局的问题。我希望一个按钮的宽度与其下方的其他几个按钮的宽度相同。Something just like this rough plan.边缘是屏幕的边界。

抱歉 link 这是我的第一个问题。我尝试在 X 轴上使用不同的单元格宽度、扩展和填充,但收效甚微,因为底部单元格移动到顶部单元格的末尾。

table.add(settingsButton).width(Value.percentWidth(0.5f, table));

The problem I have been having.

由于我对 LibGDX.

还比较陌生,所以如果能帮我解决这个问题,我将不胜感激

你可以这样做:

// w and h according to resource size (In my casee button width is 297 pixel)
float w=1000;
float h=600;

stage=new Stage(new StretchViewport(w,h));

Skin skin=new Skin(Gdx.files.internal("skin/glassy-ui.json"));

Table table=new Table();
table.setFillParent(true);
table.defaults().pad(10);
stage.addActor(table);

table.add(new TextButton("PLAY",skin)).colspan(3);
table.row().padTop(5);
table.add(new TextButton("SHOP",skin));
table.add(new TextButton("SELECT",skin));
table.add(new TextButton("SETTINGS",skin));
table.row().padTop(10);

 stage.setDebugAll(true);
 Gdx.input.setInputProcessor(stage);

输出为: