2
我想將三個文本標籤放置在屏幕上的一個確切點上(在這種情況下,在頂部可以更容易地說明問題)。所以,我有:libgdx scene2d返回錯誤的標籤高度
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);
但這裏是我得到:
這究竟是爲什麼?爲什麼不能getPrefHeight()返回標籤的正確高度?如何在沒有這些的情況下定位標籤?
這沒有效果。 'getPrefHeight()'在調用'layout()'之前和之後返回相同(不正確)的值。 – TimSim 2014-12-21 08:58:19