libgdx tablelayout坏调整大小

时间:2014-07-28 05:32:25

标签: libgdx tablelayout

第一次更改屏幕按钮大小的调用是正确设置的。如果进一步更改屏幕尺寸,则按钮不成比例。

// create
...
table = new Table();
stage.add(table);
table.setFillParent(true);
playBtn = new TextButton("PLAY", this.btnStyle);
linkBtn = new TextButton("LIKE", this.btnStyle);
this.grid.add(this.playBtn).right();
this.grid.add(this.linkBtn).left();
...

// resize method
...
stage.getViewport().update(width, height, true);
table.invalidateHierarchy();

float btnWidth = this.windowWidth / 3;
float btnHeight = btnWidth / 2;
table.getCell(this.playBtn).width(btnWidth).height(btnHeight).padRight(btnWidth / 6);
table.getCell(this.linkBtn).width(btnWidth).height(btnHeight).padLeft(btnHeight / 6);
...

结果:

enter image description here


调整大小后:
enter image description here


每当您更改屏幕尺寸时,我都会尝试创建一个屏幕

// resize method
...
if (resized) {
   this.game.setScreen(new MainMenu(this.game));
   return;
}
this.resized = true;
stage.getViewport().update(width, height, true);
table.invalidateHierarchy();

float btnWidth = this.windowWidth / 3;
float btnHeight = btnWidth / 2;
table.getCell(this.playBtn).width(btnWidth).height(btnHeight).padRight(btnWidth / 6);
table.getCell(this.linkBtn).width(btnWidth).height(btnHeight).padLeft(btnHeight / 6);
...

结果: enter image description here

如何在不使用黑客的情况下实现我想要的行为?

0 个答案:

没有答案