我希望在屏幕上的一个特定位置放置三个文本标签(在这种情况下,为了更容易说明问题,放在顶部)。所以我有以下内容:
LabelStyle labelStyle = new LabelStyle(new BitmapFont(), new Color(1,1,1,1));
Label textFullSize = new Label("Line 1 of 4\nLine 2 of 4\nLine 3 of 4\nLine 4 of 4", labelStyle);
textFullSize.setFontScale(1);
textFullSize.setPosition(0, Gdx.graphics.getHeight()-textFullSize.getPrefHeight());
stage.addActor(textFullSize);
Label textHalfSize = new Label("Line small 1 of 4\nLine small 2 of 4\nLine small 3 of 4\nLine small 4 of 4", labelStyle);
textHalfSize.setFontScale(0.5f);
textHalfSize.setPosition(Gdx.graphics.getWidth()*0.15f, Gdx.graphics.getHeight()-textHalfSize.getPrefHeight());
stage.addActor(textHalfSize);
Label textDoubleSize = new Label("Line large 1 of 4\nLine large 2 of 4\nLine large 3 of 4\nLine large 4 of 4", labelStyle);
textDoubleSize.setFontScale(2);
textDoubleSize.setPosition(Gdx.graphics.getWidth()*0.25f, Gdx.graphics.getHeight()-textDoubleSize.getPrefHeight());
stage.addActor(textDoubleSize);
但这里是我得到的结果:
![错误的标签定位](https://i.imgur.com/TGY7djx.png)
layout()
之前和之后,getPrefHeight()
返回相同(不正确)的值。 - TimSim