2016-09-23 58 views

回答

3

诀窍是,而不是使用ui::Scrollview,使用一个ui::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.