Hello.
I created a loop for creating multiple Sprites and add them to ScrollView. Therefore, I need to adjust the innerContainerSize according to the number of Sprites created.
When the value of innerContainerSize is smaller than contentSize, the innerContainer will be placed at bottom of the contentSize.
Do anyone know how to place the innerContainer to the top of the view of Content in ScrollView?
This is my implementation:
std::string input = a;
std::vector vecOfFriend = split(input, ',');
int numOfFd = vecOfFriend[0].c_str()[0] - 48;
// Scrolling Menu
ui::ScrollView *scrollView = ui::ScrollView::create();
scrollView->setDirection(ui::ScrollView::Direction::VERTICAL);
scrollView->setContentSize(Size(930, 1390)); // 930, 1390
// scrollView->setInnerContainerSize(Size(1280, (2000/7) * 7));
scrollView->setBounceEnabled(false);
//scrollView->setBackGroundImage("bg6.png");
scrollView->setPosition(Vec2(95,520));
scrollView->setScrollBarEnabled(false);
this->addChild(scrollView);
int i;
int index;
for (i = 1, index = 1; i <= numOfFd * 3; i = i + 3, index++) // 4,Joe,JL,0,Ivan,IS,0,NEO,NY,0,Nic,NN,0
{
cocos2d::ui::Button* fd = cocos2d::ui::Button::create("testlist.png", "testlist.png");
Label* fdID = Label::createWithTTF(vecOfFriend[i + 1], "NotoSansCJKtc-Regular.otf", 50);
fdID->setPosition(Vec2(350,130));
fd->addChild(fdID, 0);
Label* fdName = Label::createWithTTF(vecOfFriend[i], "NotoSansCJKtc-Regular.otf", 50);
fdName->setPosition(Vec2(350,60));
fd->addChild(fdName, 0);
Sprite* status = Sprite::create("eye.png"); // vecOfFriend[i+2]
status->setPosition(Vec2(900,90));
fd->addChild(status, 0);
fd->setPosition(Vec2(scrollView->getContentSize().width / 2 ,200 * numOfFd + 110 - (200 * index))); // 1850
log("Height: %f", (fd->getContentSize()).height);
fd->addTouchEventListener(CC_CALLBACK_2(Fdpage::touchEvent,this));
scrollView->addChild(fd);
auto fdSeparator = Sprite::create("LongBarTT.png");
fdSeparator->setPosition(Vec2(scrollView->getContentSize().width / 2 ,200 * numOfFd + 110 - (200 * index) - 100));
scrollView->addChild(fdSeparator);
log("Height: %f", fd->getContentSize().height);
}
scrollView->setInnerContainerSize(Size(1280, 200 * numOfFd)); // 1280, 200 * numOfFd
Many Thanks!!!