[英]Libgdx align does not work
After scaling down "Forgot Password:(" button, seems like its cell did not scale down. The result for that is that cell contents are in the bottom left of the cell. I need it to be aligned to the center or I need to scale down the cell to content's size. 缩小“ Forgot Password :(”按钮后,好像它的单元格没有按比例缩小。结果是该单元格的内容在该单元格的左下角。我需要将其与中心对齐,或者我需要将单元缩小到内容的大小。
Here is the screenshot: 这是屏幕截图:
And the code: 和代码:
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();
What have I done wrong or missed? 我做错了什么或错过了什么?
Scaling an Actor does not adjust its preferred size. 缩放Actor不会调整其首选大小。 You have many ways to face this, choose the one you like the most.
您可以通过多种方式来面对这一问题,选择最喜欢的一种。
forgotButton.setOrigin(Align.center)
forgotButton.setOrigin(Align.center)
forgotButton.getLabel().setFontScale(.7f)
table.add(forgotButton).pad(10).prefWidth(forgotButton.getPrefWith() * .7f)
table.add(forgotButton).pad(10).prefWidth(forgotButton.getPrefWith() * .7f)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.