3

I have a Dialog :

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

I added a two button in it:

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

My problem is that I can not change the position of buttons, not even if the imposed manually the buttons remain in the same position.

how could I do to solve the problem?

Thank you

1 Answers1

5

The buttons of a libgdx dialog get added to the ButtonTable of the Dialog, you can get this table by calling getButtonTable() method and then arrange the buttons like you would do it with any other Table.

The following code would place goButton below the stopButton for example:

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

If you want to fine-tune the layout more, you could just add the buttons to the table and use some TableLayout methods, like for example the below code would add some padding:

dialog.getButtonTable().add(stopButton).pad(20);
dialog.getButtonTable().add(goButton).pad(20);
donfuxx
  • 11,277
  • 6
  • 44
  • 76
  • I'm having problems trying to construct a dialog with all the buttons aligned to the right of the dialog itself. Is there any way to do that? – Daniele Jul 14 '15 at 10:04
  • Yes, there is a way by using .right() method of the table cell. Please create a new question with your example Dialog @Daniele – donfuxx Jul 14 '15 at 17:05
  • Is there a way for aligning the Title of the Dialog too? EDITED solution found: getTitleTable.setAlignment(Align.center) I'm sorry...I used .align instead of setAlignment – Luca Marzi Oct 06 '15 at 13:11