ControlSwitch按钮加到ui::ListView的一个item上,其它item不显示了
auto m_pListView = ListView::create();
m_pListView->setDirection(ui::ScrollView::Direction::VERTICAL);
m_pListView->setBounceEnabled(true);
m_pListView->setContentSize(Size(visibleSize.width, visibleSize.height));
m_pListView->setPosition(Vec2(0, 0));
m_pListView->addEventListener((ui::ListView::ccListViewCallback)CC_CALLBACK_2(HelloWorld::selectedItemEvent, this));
m_pListView->addEventListener((ui::ListView::ccScrollViewCallback)CC_CALLBACK_2(HelloWorld::selectedItemEventScrollView,this));
this->addChild(m_pListView);
Layout *custom_item = Layout::create();
custom_item->setContentSize(Size(visibleSize.width, visibleSize.height*0.35));
m_pListView->addChild(custom_item);
Label* labelTest = Label::createWithSystemFont("test for controlswitch", "Arial", 30);
labelTest->setPosition(Vec2(custom_item->getContentSize().width*0.5, custom_item->getContentSize().height*0.5));
custom_item->addChild(labelTest);
auto btSwitch = ControlSwitch::create(Sprite::create("switch_mask.png"), Sprite::create("switch_off.png"), Sprite::create("switch_on.png"), Sprite::create("switch_thumb.png"), Label::createWithSystemFont("Off", "Arial", 30), Label::createWithSystemFont("On", "Arial", 30));
btSwitch->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloWorld::menuSwitchCallback), Control::EventType::VALUE_CHANGED);
btSwitch->setPosition(Vec2(origin.x + visibleSize.width*0.25, origin.y + visibleSize.height*0.2));
custom_item->addChild(btSwitch);
Size cellSize = Size(visibleSize.width, 60);
for (int i=0;i<10;++i)
{
Button* custom_button = Button::create("item_bg.png", "item_bg.png");
custom_button->setName("Button");
custom_button->setScale9Enabled(true);
custom_button->setContentSize(cellSize);
Layout *custom_item = Layout::create();
custom_item->setContentSize(cellSize);
custom_button->setPosition(Vec2(custom_item->getContentSize().width*0.5, custom_button->getContentSize().height*0.5));
custom_item->addChild(custom_button);
m_pListView->addChild(custom_item);
Label* labelTest = Label::createWithSystemFont("test for controlswitch", "Arial", 30);
labelTest->setPosition(Vec2(cellSize.width*0.5, cellSize.height*0.5));
custom_item->addChild(labelTest);
}