2016-09-23 39 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. 
相關問題