简体   繁体   English

libgdx:标签高度多行

[英]libgdx: Label height multiple lines

I have a Label object with a text in it... 我有一个带有文本的Label对象...

Label label = new Label(text);

..and I get the height by... ..我的身高是...

label.pack();
GlyphLayout layout = label.getGlyphLayout();
float height = layout.height;

When I add them to a table I just said 当我将它们添加到表格中时,我只是说

Table t = new Table();
t.add(label).width(200).height(height); 

Currently I work on a chat window and each entry of the window is a Label containing a colored name and text, like... 目前,我在聊天窗口上工作,并且该窗口的每个条目都是一个Label,其中包含彩色的名称和文本,例如... 在此处输入图片说明

Note: The debug lines are drawn. 注意:画了调试线。 Please ignore the blue line, it's from another table in the scene 请忽略蓝线,它来自场景中的另一张桌子

Now my question : The 1-liner has a glyphlayout height of 38 and the 3-liner 139 . 现在我的问题 :1-衬里的38 glyphlayout高度和3衬垫139。 Does someone know why there's such a big gap between the 2 entries resp. 有人知道为什么两个条目之间有这么大的差距吗? why the 3-liner height doesn't seem to be correct? 为什么3线高度似乎不正确? No extra spacing / padding. 没有多余的间距/填充。

I would appreciate any ideas to solve this. 我将不胜感激任何想法来解决这个问题。

SOLVED: My post was incomplete, sorry. 求助:很抱歉,我的帖子不完整。 I set the width of the label before calling... 我在致电之前设置了标签的宽度...

label.setWidth(x); // where x was < chatbox width
label.pack();

So the GlyphLayout assumed a width which was smaller than the actual chatbox width. 因此,GlyphLayout假定的宽度小于实际聊天框的宽度。 The result is of course a bigger height... 结果当然是更大的高度了。

Thanks a lot to the libgdx IRC, especially Tomski :) 非常感谢libgdx IRC,尤其是Tomski :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM