2017-06-23 167 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

相關問題