libgdx - 如何使用包装文本获取Label [英] libgdx - how to get a Label with wrapped text

查看:134
本文介绍了libgdx - 如何使用包装文本获取Label的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了以下代码:

Label label = new Label(reallyLongString, skin);
label.setWrap(true);
label.setWidth(100); // or even as low as 10
table.add(label);
...

然而我得到的只是一条很宽的线屏幕。

and yet all I get is a very wide line that draws off the screen.

推荐答案

这与如何将标签放到合适的尺寸滑块始终具有默认宽度

您需要将该标签放入表中,并将正确的大小添加到标签所在表格的单元格中。

You need to put that label into a table and add the right size to the cell of the table where the label is.


UI小部件不设置自己的大小和位置。相反,父窗口小部件设置每个子项的大小和位置。窗口小部件提供父级可用作提示的最小,首选和最大大小。某些父窗口小部件(如Table)可以为如何调整子项的大小和位置提供约束。要在窗体中为窗口小部件指定特定大小,窗口小部件的最小,首选和最大大小将保持不变,并且在父窗口中设置大小约束。

UI widgets do not set their own size and position. Instead, the parent widget sets the size and position of each child. Widgets provide a minimum, preferred, and maximum size that the parent can use as hints. Some parent widgets, such as Table, can be given constraints on how to size and position the children. To give a widget a specific size in a layout, the widget's minimum, preferred, and maximum size are left alone and size constraints are set in the parent.

来源:来自libgdx wiki Scene2D

解决方案:

Label label = new Label(reallyLongString, skin);
label.setWrap(true);
label.setWidth(100); // or even as low as 10
table.add(label).width(10f);// <--- here you define the width

这篇关于libgdx - 如何使用包装文本获取Label的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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