2017-06-23 172 views
0

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

对不起,链接这是我的第一个问题。我尝试过使用不同的单元格宽度进行扩展,并在底部单元格移动到顶部单元格的末端时以极小的成功填充X轴。

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

The problem I have been having.

我只想欣赏的一点帮助,因为我是比较新的LibGDX解决这个问题。

回答

0

你可以这样做:

// 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); 

,输出是:

enter image description here

相关问题