Java Libgdx align不工作
缩小后“忘记密码:”(“按钮,其单元格似乎没有缩小。其结果是单元格内容位于单元格的左下角。我需要将其与中心对齐,或者我需要将单元格缩小到内容的大小 以下是截图: 以及守则:Java Libgdx align不工作,java,layout,libgdx,Java,Layout,Libgdx,缩小后“忘记密码:”(“按钮,其单元格似乎没有缩小。其结果是单元格内容位于单元格的左下角。我需要将其与中心对齐,或者我需要将单元格缩小到内容的大小 以下是截图: 以及守则: Table tableRoot = new Table(); tableRoot.setFillParent(true); tableRoot.padTop(40); tableRoot.align(Align.center); final Label hint = new Label("Wrong passwo
Table tableRoot = new Table();
tableRoot.setFillParent(true);
tableRoot.padTop(40);
tableRoot.align(Align.center);
final Label hint = new Label("Wrong password", Utility.UI_SKIN, "default-text");
hint.setAlignment(Align.center);
hint.setFontScale(1.3f);
final Label question = new Label("Return to login screen?", Utility.UI_SKIN, "default-text");
question.setAlignment(Align.center);
Table table = new Table();
final TextButton yesButton = new TextButton("Yes", Utility.UI_SKIN, "login-window-button");
final TextButton forgotButton = new TextButton("Forgot password:(", Utility.UI_SKIN, "login-window-button");
forgotButton.setTransform(true);
forgotButton.setScale(0.7f);
table.add(yesButton).pad(10).row();
table.add(forgotButton).pad(10).align(Align.center); //align here does not work
tableRoot.add(hint).growX().row();
tableRoot.add().grow().row();
tableRoot.add(question).growX().padBottom(20).row();
tableRoot.add(table).growX().row();
tableRoot.add().grow().row();
tableRoot.add().grow().row();
tableRoot.pack();
我做错了什么或错过了什么?缩放演员不会调整其首选大小。面对这个问题,你有很多方法,选择你最喜欢的方法
- 围绕演员中心缩放演员。调用
forgotButton.setOrigin(Align.center)
- 缩放按钮的字体,而不是按钮。
forgotButton.getLabel().setFontScale(.7f)
- 调整表格单元格的大小:
table.add(forgotButton).pad(10).prefWidth(forgotButton.getPrefWith()*.7f)