之前写的ExpandedListView版本号因为版本号升级这里提供Cocos2d-x 3.3Bate0 版本号

代码下载:http://download.csdn.net/detail/qqmcy/8033343

以下介绍下怎样使用。

先介绍下

DJDataObject存放数据模型的类

DayReportListAdapter 自己定义的adapter或是iOS中的cell

ListViewTest   演示样例类。

以下上代码啦

DJDataObject.h

//
//  DJDataObject.h
//  testthirdone
//
//  Created by 杜甲 on 14-6-7.
//
//#ifndef __testthirdone__DJDataObject__
#define __testthirdone__DJDataObject__#include "cocos2d.h"USING_NS_CC;class DJDataObject :public Ref
{public:CREATE_FUNC(DJDataObject);virtual bool init();std::string name;std::vector<DJDataObject*> children;void initWithNameAndChildren(std::string name,std::vector<DJDataObject*> data_vec);};#endif /* defined(__testthirdone__DJDataObject__) */

DJDataObject.cpp

//
//  DJDataObject.cpp
//  testthirdone
//
//  Created by 杜甲 on 14-6-7.
//
//#include "DJDataObject.h"bool DJDataObject::init()
{bool bRet = false;do {bRet = true;} while (0);return bRet;
}void DJDataObject::initWithNameAndChildren(std::string name,std::vector<DJDataObject*> data_vec)
{this->name = name;this->children = data_vec;}

DayReportListAdapter.h

//
//  DayReportListAdapter.h
//
//
//  Created by 杜甲 on 14-6-4.
//
//#ifndef __ht_mobile_cpp__DayReportListAdapter__
#define __ht_mobile_cpp__DayReportListAdapter__#include "cocos2d.h"
#include "ui/CocosGUI.h"
#include "DJTreeNodeInfo.h"USING_NS_CC;class DayReportListAdapter :public ui::Layout
{public:CREATE_FUNC(DayReportListAdapter);virtual bool init();ui::Text* organName;ui::Text* prem_day;ui::Text* prem_month;ui::ImageView* in_Image;void  setBackGround(int treeDepthLevel);Vec2 preVec2;float preOffsetX;typedef std::function<void(Ref*, Vec2 offset_vec2)> ccAdapterCallback;void addEventListener(const ccAdapterCallback& callback);ccAdapterCallback _eventCallback;bool  isMoving_HORIZONTAL;Size winSize;};#endif /* defined(__ht_mobile_cpp__DayReportListAdapter__) */

DayReportListAdapter.cpp

//
//  DayReportListAdapter.cpp
//
//
//  Created by 杜甲 on 14-6-4.
//
//#include "DayReportListAdapter.h"#include "VisibleRect.h"bool DayReportListAdapter::init()
{bool bRet = false;do {CC_BREAK_IF(!ui::Layout::init());setLayoutType(cocos2d::ui::Layout::Type::RELATIVE);setBackGroundColorType(ui::Layout::BackGroundColorType::SOLID);winSize = Director::getInstance()->getWinSize();setTouchEnabled(true);float topLength = 30;in_Image = ui::ImageView::create("CloseNormal.png");in_Image->setScale(VisibleRect::getImageScale());in_Image->setTouchEnabled(true);addChild(in_Image);auto rp_image = ui::RelativeLayoutParameter::create();rp_image->setRelativeName("rp_image");float offset = -in_Image->getContentSize().width * 2/3 *(1- VisibleRect::getImageScale());rp_image->setMargin(ui::Margin(-in_Image->getContentSize().width * 2/3 *(1- VisibleRect::getImageScale()),0,0,0));rp_image->setAlign(cocos2d::ui::RelativeLayoutParameter::RelativeAlign::PARENT_LEFT_CENTER_VERTICAL);in_Image->setLayoutParameter(rp_image);organName = ui::Text::create();organName->setFontSize(38 * VisibleRect::getImageScale());organName->setColor(Color3B::BLACK);addChild(organName);auto rp_organName = ui::RelativeLayoutParameter::create();rp_organName->setRelativeName("rp_organName");rp_organName->setRelativeToWidgetName("rp_image");rp_organName->setMargin(ui::Margin(1 * VisibleRect::getImageScale() + offset,topLength,0,0));rp_organName->setAlign(cocos2d::ui::RelativeLayoutParameter::RelativeAlign::LOCATION_RIGHT_OF_CENTER);organName->setLayoutParameter(rp_organName);prem_month = ui::Text::create();prem_month->setFontSize(38 * VisibleRect::getImageScale());prem_month->setTextHorizontalAlignment(cocos2d::TextHAlignment::LEFT);prem_month->setColor(Color3B::BLACK);addChild(prem_month);auto rp_prem_month = ui::RelativeLayoutParameter::create();rp_prem_month->setAlign(cocos2d::ui::RelativeLayoutParameter::RelativeAlign::PARENT_TOP_RIGHT);rp_prem_month->setRelativeName("rp_prem_month");rp_prem_month->setMargin(ui::Margin(0,topLength,50*VisibleRect::getImageScale(),0));prem_month->setLayoutParameter(rp_prem_month);auto center = ui::Layout::create();center->setSize(Size(1, 1));addChild(center);auto rp_center = ui::RelativeLayoutParameter::create();rp_center->setRelativeName("rp_center");rp_center->setAlign(cocos2d::ui::RelativeLayoutParameter::RelativeAlign::CENTER_IN_PARENT);center->setLayoutParameter(rp_center);prem_day = ui::Text::create();prem_day->setTextHorizontalAlignment(cocos2d::TextHAlignment::LEFT);prem_day->setFontSize(38 * VisibleRect::getImageScale());prem_day->setAnchorPoint(Vec2::ANCHOR_MIDDLE_LEFT);prem_day->setSize(Size(100, 50));prem_day->setColor(Color3B::BLACK);addChild(prem_day);auto rp_prem_day = ui::RelativeLayoutParameter::create();rp_prem_day->setRelativeToWidgetName("rp_center");rp_prem_day->setAlign(cocos2d::ui::RelativeLayoutParameter::RelativeAlign::PARENT_TOP_CENTER_HORIZONTAL);//  rp_prem_day->setRelativeToWidgetName("rp_prem_month");rp_prem_day->setMargin(ui::Margin(30,topLength,0,0));prem_day->setLayoutParameter(rp_prem_day);auto bottom_color = ui::Layout::create();bottom_color->setSize(Size(winSize.width, 1));bottom_color->setBackGroundColorType(ui::Layout::BackGroundColorType::SOLID);bottom_color->setBackGroundColor(Color3B::BLACK);addChild(bottom_color);auto rp_bottom_color = ui::RelativeLayoutParameter::create();rp_bottom_color->setAlign(cocos2d::ui::RelativeLayoutParameter::RelativeAlign::PARENT_BOTTOM_CENTER_HORIZONTAL);rp_bottom_color->setMargin(ui::Margin(0,0,0,1));bottom_color->setLayoutParameter(rp_bottom_color);bRet = true;} while (0);return bRet;}void DayReportListAdapter::setBackGround(int treeDepthLevel)
{log("treeDepthLevel = %d",treeDepthLevel);switch (treeDepthLevel) {case 0:setBackGroundColor(Color3B(209, 238, 252));break;case 1:setBackGroundColor(Color3B(224, 248, 216));break;case 2:break;default:break;}
}void DayReportListAdapter::addEventListener(const ccAdapterCallback &callback)
{_eventCallback = callback;}

ListViewTest.h

//
//  ListViewTest.h
//  testthirdone
//
//  Created by 杜甲 on 14-6-9.
//
///**  演示样例Demo*/#ifndef __testthirdone__ListViewTest__
#define __testthirdone__ListViewTest__#include "cocos2d.h"
#include "ui/CocosGUI.h"
#include "DJDataObject.h"
#include "DJListView.h"USING_NS_CC;
using namespace ui;class ListViewTest  : public ui::Layout , public DJListViewDataSource , public DJListViewDelegate
{
public:CREATE_FUNC(ListViewTest);virtual bool init();private:std::vector<DJDataObject*> data_vec;virtual ssize_t treeViewNumberOfChildrenOfItem(DJListView *treeView , void *item) ;virtual ui::Layout *treeViewAndCellForItemAndTreeNodeInfo(DJListView *treeView , void *item , DJTreeNodeInfo *treeNodeInfo);virtual void* treeViewAndChildOfItem(DJListView *treeView , int index , void *item);Size winSize;virtual void treeViewWillDisplayCellForItemTreeNodeInfo(DJListView *treeView , ui::Layout *adapter , void *item , DJTreeNodeInfo *treeNodeInfo) ;};#endif /* defined(__testthirdone__ListViewTest__) */

ListViewTest.cpp

//
//  ListViewTest.cpp
//  testthirdone
//
//  Created by 杜甲 on 14-6-9.
//
//#include "ListViewTest.h"
#include "DJTreeNode.h"
#include "DJTreeNodeInfo.h"
#include "DayReportListAdapter.h"bool ListViewTest::init()
{bool bRet = false;do {CC_BREAK_IF(!ui::Layout::init());winSize = Director::getInstance()->getWinSize();setBackGroundColorType(ui::Layout::BackGroundColorType::SOLID);setBackGroundColor(Color3B(18, 23, 222));std::vector<DJDataObject*>temp1;std::vector<DJDataObject*>temp2;std::vector<DJDataObject*>temp3;std::vector<DJDataObject*>temp4;DJDataObject* data7 = DJDataObject::create();data7->retain();//initWithNameAndChildren 參数1:当前数据内容, 參数2 :子集data7->initWithNameAndChildren("数据1-1-1", temp4);temp1.push_back(data7);DJDataObject* data3 = DJDataObject::create();data3->retain();data3->initWithNameAndChildren("数据1-1", temp1);DJDataObject* data4 = DJDataObject::create();data4->retain();data4->initWithNameAndChildren("数据1-2", temp4);for (int i = 0; i < 7; i++){DJDataObject* data6 = DJDataObject::create();data6->retain();data6->initWithNameAndChildren("数据h", temp3);temp2.push_back(data6);}DJDataObject* data1 = DJDataObject::create();data1->retain();data1->initWithNameAndChildren("数据r", temp2);DJDataObject* data = DJDataObject::create();data->retain();std::vector<DJDataObject*>temp;temp.push_back(data3);temp.push_back(data4);data->initWithNameAndChildren("数据12", temp);data_vec.push_back(data);data_vec.push_back(data1);auto winSize = Director::getInstance()->getWinSize();auto listView1 = DJListView::create();listView1->setDJListViewDataSource(this);listView1->setDJListViewDelegate(this);listView1->setSize(winSize);listView1->addExpandedListView(data_vec);addChild(listView1);bRet = true;} while (0);return bRet;
}void ListViewTest::treeViewWillDisplayCellForItemTreeNodeInfo(DJListView *treeView, ui::Layout *adapter, void *item, DJTreeNodeInfo *treeNodeInfo)
{if (treeNodeInfo->treeDepthLevel == 0) {adapter->setBackGroundColor(Color3B(150, 100, 200));}else if (treeNodeInfo->treeDepthLevel == 1){adapter->setBackGroundColor(Color3B(100, 100, 100));}else if (treeNodeInfo->treeDepthLevel == 2){adapter->setBackGroundColor(Color3B(100, 150, 150));}}ssize_t ListViewTest::treeViewNumberOfChildrenOfItem(DJListView *treeView , void *item)
{if (item == nullptr) {return data_vec.size();}DJDataObject* data =  static_cast<DJDataObject*>(item);return data->children.size();
}ui::Layout* ListViewTest::treeViewAndCellForItemAndTreeNodeInfo(DJListView *treeView , void *item , DJTreeNodeInfo *treeNodeInfo)
{DJDataObject* dobject = static_cast<DJDataObject*>(item) ;auto tableLayout1 = DayReportListAdapter::create();tableLayout1->setSize(Size(winSize.width, 100));tableLayout1->setBackGroundColorType(ui::Layout::BackGroundColorType::SOLID);
//    tableLayout1->setBackGround(treeNodeInfo->treeDepthLevel);
//    tableLayout1->setBackGroundColor(Color3B(189, 203, 222));
//    listView->pushBackCustomItem(tableLayout1);tableLayout1->organName->setString(dobject->name);tableLayout1->prem_day->setString(StringUtils::format("%d",333));tableLayout1->prem_month->setString("fffff");return tableLayout1;
}
void* ListViewTest::treeViewAndChildOfItem(DJListView *treeView , int index , void *item)
{DJDataObject* data = static_cast<DJDataObject*>(item);if (item == nullptr) {return data_vec.at( index );}return data->children.at( index );
}

效果:

转载于:https://www.cnblogs.com/lxjshuju/p/7268022.html

Cocos2d-x 3.3Bate0 ExpandedListView相关推荐

  1. Improve Performance and Reduce Memory with PVRTC Textures and Cocos2d

    转载自:http://www.uchidacoonga.com/2011/07/pvrtc-textures-and-cocos2d/ Hello everyone! A few months hav ...

  2. 【Cocos2d开发】Cocos2d下安卓环境的搭建

    在进行Cocos2d游戏开发前 我们先来配置一下环境,我们先来准备一下工具,我们所需要的工具分别为: 1.Cocos2d引擎 2.JDK 3.SDK 4.NDK 5.ANT 6.ADT 1.下载Coc ...

  3. cocos2d 从v1.x升级到v2.x需要注意的几个地方

    首先v1.x一些CCNode定位函数实现的有问题,导致返回的CCPoint的x坐标不正确(超出320后无变化),怀疑是其对屏幕旋转判断的不正确;而且这种现象在iOS 7.1之前的模拟器中运行都正常,在 ...

  4. cocos2d游戏jsc文件格式解密,SpideMonkey大冒险

    点击上方↑↑↑蓝字[协议分析与还原]关注我们 " 介绍cocos2d游戏中常用的jsc格式文件的解密." 01 - 在破解游戏应用中,经常会碰到后缀为jsc的文件,这是基于coco ...

  5. 如何优化cocos2d程序的内存使用和程序大小:第一部分

    译者: 在我完成第一个游戏项目的时候,我深切地意识到"使用cocos2d来制作游戏的开发者们,他们大多会被cocos2d的内存问题所困扰".而我刚开始接触cocos2d的时候,社区 ...

  6. Cocos2d入门--3--向量的应用

    小球向一个方向持续运动的Demo HelloWorldScene.h ...... //设置一个protected的属性 protected:cocos2d::Vec2 _vec; ...... He ...

  7. Cocos2d之Action类详解

    一.声明 文章中使用到的cocos2d的源代码的版本是cocos2d-x-3.3rc0. 二.主要内容 [Action类简介] 在cocos2d中,Action类是所有动作的基类.Action类继承了 ...

  8. [cocos2d-x]cocos2d和cocos2d-x的一些通用性

    不得不说要说总结,因为Cocos2d-X的代码和Cocos2d-iphone两个引擎除了语言不同外(Cocos2d-X使用C++,Cocos2d-iphone使用Object-C)可以说没有其他差异. ...

  9. Cocos2d中从场景切换到UIViewController视图方法总结

    第一种:直接从场景切换到UIViewController视图(网上流传的版本) - (void) showUIViewController:(UIViewController *) controlle ...

最新文章

  1. 2022-2028年中国地铁广告行业研究及前瞻分析报告
  2. 关于优酷开发sdkdemo的布局
  3. JAVA mysql存数组_JAVA数组怎么存放数据库的元素
  4. word2010添加b5纸张大小_纸张幅面规格尺寸你了解吗?
  5. cocos2d-x 3.0rc2中读取sqlite文件
  6. CPU时间分片、多线程、并发和并行
  7. 编写一个项目开发文档
  8. React学习笔记—表单
  9. Scaled Exponential Linear Unit
  10. 矩表 - 现代数据分析中必不可少的报表工具
  11. 教你如何在微信浏览器下载APP
  12. 实用好用的在线二维码生成器有哪些?
  13. 全开源、低代码开发平台:搭建工作管理系统
  14. 史上最全软件测试Web测试要点,吐血整理。
  15. ICO和区块链的关系
  16. (145)光线追踪距离场柔和阴影
  17. AM335x SPL(一)
  18. 【Mybatis】Mybatis将String类型的0存到数据库中的number类型字段中,变成了空;
  19. 记录一次nodejs爬取《17吉他》所有吉他谱(只探讨技术)
  20. linux红帽子怎么设置防火墙,RedHat Linux如何设置防火墙

热门文章

  1. java实战:jsp快速实现简单易用的信息登记与查询功能
  2. 腾讯乐享成为国内首家通过ISO27001认证的企业社区平台
  3. SIFT特征原理简析(HELU版)
  4. CSS img正方形图片
  5. pyqt 控件焦点_PyQt5(2)——调整布局(布局管理器)第一个程序
  6. Fiddler如何开启显示源IP地址
  7. 什么样的团队才是优秀的团队
  8. 2022年熔化焊接与热切割免费试题及熔化焊接与热切割考试总结
  9. 复旦计算机课考勤,复旦管院苏勇教授:当MBA遇上“读脸考勤”
  10. 导入properties文件地方出错