Dialog的对象位置Libgdx

3

我有一个对话框:

Dialog dialog=new Dialog("",style);
dialog.setSize(400, 500);
dialog.setPosition(Gdx.graphics.getWidth()/2-200, Gdx.graphics.getHeight()/2-300);

我在其中添加了两个按钮:

 dialog.button(stopButton);
 dialog.button(goButton);

我的问题是我无法更改按钮的位置,即使我手动设置位置,按钮仍然保持在相同的位置。

我该如何解决这个问题?

谢谢。

1个回答

5
The buttons in a libgdx dialog are added to the ButtonTable of the Dialog. You can retrieve this table by calling the getButtonTable() method and arrange the buttons as you would with any other Table.
For example, the following code places the goButton below the stopButton:
dialog.button(stopButton);
dialog.getButtonTable().row();
dialog.button(goButton);

如果你想更精细地调整布局,你可以将按钮添加到表格中并使用一些TableLayout方法。例如,下面的代码将添加一些填充:

dialog.getButtonTable().add(stopButton).pad(20);
dialog.getButtonTable().add(goButton).pad(20);

我在尝试构建一个对话框时遇到了问题,想让所有按钮都对齐到对话框的右侧。有没有什么方法可以实现这个需求? - Daniele
是的,可以使用表格单元格的.right()方法来实现。请创建一个新问题,并附上您的示例对话 @Daniele - donfuxx
有没有办法将对话框的标题也对齐?编辑找到解决方案:getTitleTable.setAlignment(Align.center)很抱歉……我错用了.align而不是setAlignment。 - Luca Marzi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接