ListView的使用
来源:互联网 发布:现在开淘宝网店赚钱吗 编辑:程序博客网 时间:2024/06/06 05:25
// 创建一个ListView
auto listView = ListView::create();
// 设置ListView的方向,本例为VERTICAL(垂直)
listView->setDirection(ScrollView::Direction::VERTICAL);
// 设置ListView的背景图片
listView->setBackGroundImage("green_edit.png");
// 设置背景图片作为九宫格填充
listView->setBackGroundImageScale9Enabled(true);
// 设置ListView的ContentSize
listView->setContentSize(Size(480, 260));
// 设置ListView的位置
listView->setPosition(Vec2((visibleSize.width - listView->getContentSize().width) / 2.0f,
(visibleSize.height - listView->getContentSize().height) / 2.0f));
// 添加事件监听器(ListView)
listView->addEventListener([=](Ref *pSender, ListView::EventType type){
switch (type)
{
case ListView::EventType::ON_SELECTED_ITEM_START:
{
ListView* listView = static_cast<ListView*>(pSender);
log("select child start index = %ld", listView->getCurSelectedIndex());
break;
}
case ListView::EventType::ON_SELECTED_ITEM_END:
{
ListView* listView = static_cast<ListView*>(pSender);
log("select child end index = %ld", listView->getCurSelectedIndex());
break;
}
default:
break;
}
});
// 添加事件监听器(ScrollView)
listView->addEventListener([=](Ref* pSender, ScrollView::EventType type){
switch (type) {
case ScrollView::EventType::SCROLL_TO_BOTTOM:
log("SCROLL_TO_BOTTOM");
break;
case ScrollView::EventType::SCROLL_TO_TOP:
log("SCROLL_TO_TOP");
break;
default:
break;
}
});
// 将ListView添加为当前层的子节点
this->addChild(listView);
// 添加自定义item(10个Button)
for (int i = 0; i < 10; ++i)
{
// 创建一个Layout,用来添加Button
Layout *custom_item = Layout::create();
// 设置Layout的ContentSize和Button的ContentSize一致
custom_item->setContentSize(custom_button->getContentSize());
// 将Layout添加为ListView的子节点
listView->addChild(custom_item);
// 创建一个Button
Button* custom_button = Button::create("button.png", "buttonHighlighted.png");
// 设置Button的Name
custom_button->setName("Title Button");
// 设置Button是否九宫格填充
custom_button->setScale9Enabled(true);
// 设置Button的ContentSize
custom_button->setContentSize(Size(200, 60));
// 设置Button的TitleText为对应_array的文本内容
custom_button->setTitleText(StringUtils::format("listview_item_%d", i));
// 设置Button的文本字体大小
custom_button->setTitleFontSize(24);
// 设置Layout的坐标位置
custom_button->setPosition(Vec2(custom_item->getContentSize().width / 2.0f, custom_item->getContentSize().height / 2.0f));
// 将Button添加为Layout的字节
custom_item->addChild(custom_button);
}
- listview 的使用
- ListView的使用
- ListView的使用技巧
- delphi ListView 的使用
- ListView的使用
- EasyMF ListView 的使用
- ListView的使用
- listview的使用1
- ListView的使用
- ListView控件的使用
- ListView的使用
- Listview 的基本使用
- ListView的使用1
- ListView的使用2
- android ListView的使用
- listView的使用
- VB ListView的使用
- ListView 控件的使用
- Hibernate
- 解析解与数值解的区别
- Linux 获取制定目录的文件数(递归)
- KityMinder Editor ========== ## 简介 KityMinder Editor 是一款强大、简洁、体验优秀的脑图编辑工具,适合用于编辑树/图/网等结构的数据。
- Dotnet2.0中string 转 char *
- ListView的使用
- 存储过程学习
- 聊一下“深度学习”的基本思想
- Linux下安装MySQL的流程及部分错误异常处理
- 素数求和问题
- px和em区别-在font-size的 css 的使用
- Widget中Layout的使用
- html的http消息
- MenuItemImage的使用