gpt4 book ai didi

java - 如何获得带有包装文本的标签?

转载 作者:搜寻专家 更新时间:2023-10-30 20:56:22 25 4
gpt4 key购买 nike

我试过以下代码:

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

但我得到的只是一条从屏幕上拉下来的很宽的线。如何获取带有换行文本的标签?

最佳答案

这与 slider always has default width 中看到的问题相同或 "Slider always has default width" .

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

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.

来源:From the 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

关于java - 如何获得带有包装文本的标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18557448/

25 4 0