I made a ListView
instance and add addEventListenerScrollView
.
and I added some items to ListView.
then SCROLLVIEW_EVENT_SCROLLING
event is occured.
but inner container position is wrong value.
I made a simple test code here.
bool TestScene::init()
{
if (!Layer::init()) return false;
_list = ListView::create();
_list->setSize(Size(240, 200));
_list->setDirection(SCROLLVIEW_DIR_VERTICAL);
auto layout = Layout::create();
layout->setSize(Size(240.0f, 150.0f));
_list->setItemModel(layout);
_list->addEventListenerScrollView(this, scrollvieweventselector(TestScene::testScroll));
addChild(_list);
_list->pushBackDefaultItem();
_list->pushBackDefaultItem();
scheduleOnce(schedule_selector(TestScene::checkListPosition), 1.f);
return true;
}
void TestScene::testScroll(Object *pSender, ScrollviewEventType type)
{
if (type == ScrollviewEventType::SCROLLVIEW_EVENT_SCROLLING){
// this prints "x = 0.000000, y = 0.000000"
log("x = %f, y = %f", _list->getInnerContainer()->getPositionX(), _list->getInnerContainer()->getPositionY());
}
}
void TestScene::checkListPosition(float dt)
{
// this prints "x = 0.000000, y = -100.000000"
log("x = %f, y = %f", _list->getInnerContainer()->getPositionX(), _list->getInnerContainer()->getPositionY());
}
so, when adding items to list, I can’t calculate properly with scroll position.