cocos2d_x+lua【4.1】 ——ListView的使用

一、创建列表层

  
  
  1. function create_listview()
  2. local layer = CCLayerColor:layerWithColorWidthHeight(ccc4(255, 0, 0, CORLORLAYERENABLE),640, 200)
  3. layer:setAnchorPoint(CCPointMake(0,0))
  4. layer:setIsRelativeAnchorPoint(true)
  5. --anchorPoint这个属性虽然是属于CCNode的、但CCLayer设置anchorPoint没有效果、
  6. --CCLayeranchorPoint被默认设定在(0, 0)、在setAnchorPoint之前要先设置setIsRelativeAnchorPoint = true
  7. layer:setPosition(PT(165,120))
  8. -- 两种排列 CCListViewModeHorizontal 水平 CCListViewModeVertical 竖直
  9. m_pList = CCListView:viewWithMode(CCListViewModeHorizontal)
  10. -- 初始化控件
  11. ListView m_pList:setContentSize(CCSize(640,200))
  12. m_pList:setDelegateName('testListView')
  13. m_pList:setAnchorPoint(CCPointMake(0,0))
  14. m_pList:setPosition(PT(0,0))  --两种分隔 CCListViewCellSeparatorStyleNone CCListViewCellSeparatorStyleSingleLine m_pList:setSeparatorStyle(CCListViewCellSeparatorStyleNone) layer:addChild(m_pList) return layerend

  
  
  1. <span style="font-size: 2em; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px;">二、实现的方法</span>

–返回有多少页

  
  
  1. function testListView_CCListView_numberOfCells(listview,data)
  2.     data.nNumberOfRows= listview:size()
  3. end

–listview在滑动中

  
  
  1. function testListView_triggerDidScrollToRow(nRow)
  2.     local i = nRow
  3.     cclog("scrolling:"..i)
  4. end

–cell被选中

  
  
  1. function testListView_triggerDidClickCellAtRow(nRow)  
  2.  local i = nRow
  3. cclog("clicked:"..i)
  4. end

–将listview层的触摸打开

  
  
  1. function setTouch_openLayer(layer)
  2. layer:registerScriptTouchHandler(onTouch_openLayer,nil,-129,nil)
  3. layer:setIsTouchEnabled(true)
  4. end

–具体显示什么内容,每一页的内容

  
  
  1. function testListView_triggerCellForRow(listview,data)
  2.     m_nCurrnetPage = data.nRow + 1   --data.nRow0开始
  3.     local cell = CCListViewCell:node()
  4.     cell:setOpacity(0)
  5.     cell:setContentSize(m_pList:getContentSize())
  6.     cell:setSelectionColor(ccc4(0, 0, 0, 0))
  7.     data.cell = cell
  8.     _curCell = cell
  9.     local listItemSize = CCSize:new(m_pList:getContentSize().width , m_pList:getContentSize().height)
  10.     for n = 1, data.nNumberOfRows do
  11.     cell:addChild(xxxxxx)
  12.     end
  13. end

三、listview的使用

  
  
  1. listview_layer = create_listview()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值