如何获得带有包装文本的标签? [英] How to get a Label with wrapped text?

查看:18
本文介绍了如何获得带有包装文本的标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过以下代码:

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. How to get a Label with wrapped text?

推荐答案

这与 slider always has default width"滑块始终具有默认宽度".

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

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

这篇关于如何获得带有包装文本的标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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