Dialog's object position Libgdx

假如想象 提交于 2019-12-11 03:16:33

问题


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:


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


来源:https://stackoverflow.com/questions/26074089/dialogs-object-position-libgdx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!