libGDX 按钮布局,没有间距



我正在使用表格来布局我的菜单按钮,但按钮之间的间距足以让汽车通过。 我该怎么做才能更好地控制明显的单元格填充?我搜索了 StackOverflow 帖子,通读了 API,在表格和 actor 之后键入"."来浏览自动完成,手动调整皮肤文件中的值,并在 Github 上查看其他人的项目。 我尝试过的一些方法包括sizeBy((,scaleBy((,pad((,setFillParent((,space((,fillY((和grow((

一个有用的答案将描述如何让按钮堆叠在一起,触摸。

Gdx.input.setInputProcessor(stage); 
// Create a table that fills the screen. Everything else will go inside this table.
Table table = new Table();
table.setFillParent(true);
table.setDebug(true);
stage.addActor(table);
table.setBackground(new TiledDrawable(background));
//create buttons
TextButton newGame = new TextButton("New Game", skin);
TextButton preferences = new TextButton("Preferences", skin);
TextButton exit = new TextButton("Exit", skin);

TextButtonStyle tbs = new TextButtonStyle(newGame.getStyle());
NinePatch np = new NinePatch(skin.getPatch("button"));
np.setColor(np.getColor().sub(0f, 0f, 0f, .4f)); 
tbs.up = new NinePatchDrawable(np);
newGame.setStyle(tbs);        
preferences.setStyle(tbs);
exit.setStyle(tbs);

table.bottom().right().padBottom(40f).padRight(40f);
//add buttons to table
table.add(newGame).bottom().right().fillX().uniformX();
table.row();//.pad(1, 0, 1, 0);
table.add(preferences).bottom().right().fillX().uniformX();
table.row();
table.add(exit).bottom().right().fillX().uniformX();

这是我的皮肤。 我使用了示例"生锈的机器人 UI",但它没有严格裁剪它的按钮图像。 尝试了另一个,看到了我正在寻找的堆叠。

最新更新