ui::Scrollview
の代わりに、ui::ListView
を使用する代わりに、ui::Text
という1つの項目しか使用しないでください。これにより、ui::Text
のテキストコンテンツを変更するときに、スクロールしてコンテナのサイズを動的に変更できます。
キーは、親ui::ListView
と同じサイズと0までの高さにui::Text
の幅を設定する)であり、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.