我是 JME3 游戏引擎的新手,但我非常了解 Android XML GUI 布局。我这里有一个简单的布局,我不知道哪里出了问题。这是我的 XML 代码:
<?xml version="1.0" encoding="UTF-8"?>
<nifty xmlns="http://nifty-gui.sourceforge.net/nifty-1.3.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://nifty-gui.sourceforge.net/nifty-1.3.xsd
http://nifty-gui.sourceforge.net/nifty-1.3.xsd">
<useControls filename="nifty-default-controls.xml" />
<useStyles filename="nifty-default-styles.xml" />
<screen id="start" controller="com.jasoncrosby.game.farkle.gui.MenuScreenGui">
<layer id="layer" backgroundColor="#66CD00" childLayout="center">
<panel id="panel" align="center" valign="center" childLayout="center" visibleToMouse="true">
<image filename="Textures/wood_floor.png" height="95%" width="95%"/>
<panel id="panel" align="center" valign="center" childLayout="center" visibleToMouse="true">
<text text="test" font="Interface/Fonts/Eraser.fnt"></text>
</panel>
</panel>
</layer>
</screen>
在我开始显示文本之前一切正常。我尝试了不同的对齐方式,并尝试将文本移动到不同的面板中,但无论我做什么,文本都不会位于屏幕中央。它总是在左上角,到目前为止我只能看到文本的右下部分。我确定它必须是简单的东西,但由于我是新手,所以我没有注意到任何东西。提前感谢您的帮助。
最佳答案
您可能使用的是旧版 Nifty。您的第一个 id="panel"面板使用 childLayout="center"并且它有两个子元素(一个图像和另一个面板)。这在 1.3.1 之前的 Nifty 版本中不受支持。
这是来自 Nifty Manual PDF 的引述:
Another thing that has been improved in Nifty 1.3.1 is that childLayout=“center“ now supports more than one child element! In versions prior 1.3.1 childLayout=“center“ would only support a single child elements and odd things would happen to the other elements. This has now been improved as well and childLayout=“center“ supports more than one child element.
我已经用 Nifty 1.3.2 试过你的 XML,文本位于屏幕中央。
PS:与您的问题无关:对多个元素使用相同的 id 不是一个好主意(您有两个 id="panel"的面板)。不会发生任何不好的事情(除了日志中的警告)但是当您尝试执行 findElementByName() 时,您可能会遇到一些意想不到的元素。
关于java - 漂亮的 GUI 布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12920168/