libgdx align不起作用 [英] Libgdx align does not work

查看:155
本文介绍了libgdx align不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按比例缩小忘记密码:("按钮后,似乎其单元格未按比例缩小.其结果是单元格内容位于单元格的左下角.我需要将其与中心对齐或我需要将单元格缩小到内容的大小.

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.

以下是屏幕截图:

和代码:

 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?

推荐答案

缩放Actor不会调整其首选大小.您可以通过多种方式面对这一问题,选择最喜欢的一种.

Scaling an Actor does not adjust its preferred size. You have many ways to face this, choose the one you like the most.

  • 围绕演员的中心缩放演员.致电forgotButton.setOrigin(Align.center)
  • 缩放按钮的字体,而不是按钮的字体. forgotButton.getLabel().setFontScale(.7f)
  • 调整表格单元格的大小:table.add(forgotButton).pad(10).prefWidth(forgotButton.getPrefWith() * .7f)
  • scale the actor around its center. Call forgotButton.setOrigin(Align.center)
  • scale the font of the button, not the button. forgotButton.getLabel().setFontScale(.7f)
  • size the table's cell: table.add(forgotButton).pad(10).prefWidth(forgotButton.getPrefWith() * .7f)

这篇关于libgdx align不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆