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)

非常感谢!我可以再问一个问题吗?演员的原点是否位于其中心?最初原点位于位置0,0-因此它位于左下角。这正是您在屏幕截图中看到的。我的意思是..原点比什么?我以为它只是缩放、旋转等的轴心点。但实际上它似乎是d不同的是,我建议你尝试使用一个动作和缩放,或者用这个动作和不同的原点旋转你的演员。我相信你会明白什么是原点。:-)