0

我有一个ui::Textui::Layout根据内容,它会溢出。我已经查看Label::setOverflowLabel::setWrap关闭了ui::Text's virtualRenderer Label,但我没有看到使其可滚动和换行的方法。

如何ui::Text在确保正确包装文本的同时制作可滚动的?

4

1 回答 1

3

诀窍是,而不是使用ui::Scrollview,使用 aui::ListView里面只有一个项目,ui::Text. 这使您可以滚动并动态调整容器大小,以便在更改ui::Text.

关键是 a) 将其宽度设置为ui::Text与其父级相同的大小,ui::ListView并将高度设置为 0 和 b)my_listview->requestDoLayout()每当文本内容发生更改时调用列表视图,以便可滚动区域反映这一点。

这是一个示例,说明如何将大正文滚动到较小的正文中ui::Panel

ui::ListView* listview = ListView::create();
my_scene->addChild(listview);
listview->setContentSize({300, 500}); //give it whatever size

ui::Text* text = ui::Text::create("[multiline content]", "fontName.ttf", 16);
text->setTextAreaSize({300, 0}); //use that same size, but use 0 height. This auto sets overflow and wrap in the backend
listview->addChild(text);
listview->requestDoLayout(); //this triggers resizing the listview to accommodate the
                             //string content. Needs to happen each time you
                             //text->setString(new_content) too.
于 2016-09-23T06:09:55.133 回答