出现的主要情况是 我点击在ControlButton上面滑动的时候 ControlButton会将事件吃掉 所以listview就不会滑动 自己也在网络上面查了一些相关资料 最有用的应该是 这一篇文章 。但是使用了里
mOtherGameListView = cocos2d::ui::ListView::create(); mOtherGameListView->setDirection(ui::ScrollView::Direction::VERTICAL);//设置ListView布局方向 mOtherGameListView->setBounceEnabled(false);//设置反弹效果 mOtherGameListView->setAnchorPoint(Vec2(0, 0)); mOtherGameListView->setContentSize(Size(m_other_width, 440)); mOtherGameListView->setInnerContainerSize(Size(m_other_width, 440)); mOtherGameListView->setBackGroundImageScale9Enabled(true);//设置九宫格 mOtherGameListView->setPosition(Vec2(0, 0)); mOtherGameListView->ignoreContentAdaptWithSize(false);//开启锚点设置,false可更改锚点,true不可更改,Layer默认为point(0,0),其他Node为Point(0.5,0.5) mOtherGameListView->setGravity(cocos2d::ui::ListView::Gravity::CENTER_VERTICAL); m_other_gameLayer->addChild(mOtherGameListView); mOtherGameListView->addEventListener((ui::ListView::ccListViewCallback)CC_CALLBACK_2(YYNewGameListLayer::selectedItemEvent, this));
void YYNewGameListLayer::selectedItemEvent(Ref *pSender, cocos2d::ui::ListView::EventType type){ switch (type) { case cocos2d::ui::ListView::EventType::ON_SELECTED_ITEM_START: { cocos2d::ui::ListView* listView = static_cast<cocos2d::ui::ListView*>(pSender); CC_UNUSED_PARAM(listView); CCLOG("select child start index = %ld", listView->getCurSelectedIndex()); cocos2d::ui::Layout* item = (cocos2d::ui::Layout *)listView->getItem(listView->getCurSelectedIndex()); //item->setScale(1.1f); break; } case cocos2d::ui::ListView::EventType::ON_SELECTED_ITEM_END: { cocos2d::ui::ListView* listView = static_cast<cocos2d::ui::ListView*>(pSender); CC_UNUSED_PARAM(listView); cocos2d::ui::Layout* item = (cocos2d::ui::Layout *)listView->getItem(listView->getCurSelectedIndex()); if (roomSelectLayer == NULL) { onClickGame(item->getTag()); } CCLOG("select child end index = %ld", listView->getCurSelectedIndex()); break; } default: break; } }
for (size_t i = 0; i < mOtherGameList.size(); i++) { ui::Layout * mItem = ui::Layout::create(); mItem->setContentSize(Size(318, 110)); mItem->setTouchEnabled(true); CGameKindItem *pGameKindItem = mOtherGameList[i]; ControlButton *btnGame1 = createButton( stringFormatC("game_btn_nor_%d.png", pGameKindItem->m_GameKind.wKindID).c_str(), stringFormatC("game_btn_click_%d.png", pGameKindItem->m_GameKind.wKindID).c_str(), 0, 0, this, cccontrol_selector(YYNewGameListLayer::onGameBtnClick)); btnGame1->setPosition(Vec2(mItem->getContentSize().width / 2, mItem->getContentSize().height / 2)); btnGame1->setTag(pGameKindItem->m_GameKind.wKindID); btnGame1->setEnabled(false); mItem->addChild(btnGame1); mItem->setTag(pGameKindItem->m_GameKind.wKindID); mOtherGameListView->pushBackCustomItem(mItem); }