`
mmdev
  • 浏览: 12925571 次
  • 性别: Icon_minigender_1
  • 来自: 大连
文章分类
社区版块
存档分类
最新评论

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

 
阅读更多

oDustGgg个人原创、欢迎转载、转载请注明出处、http://blog.csdn.net/odustggg/article/details/8171230

一、创建列表层

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

二、实现的方法

--返回有多少页
function testListView_CCListView_numberOfCells(listview,data)
    data.nNumberOfRows= listview:size()   
end
--listview在滑动中
function testListView_triggerDidScrollToRow(nRow)
    local i = nRow
    cclog("scrolling:"..i) 
end
--cell被选中
function testListView_triggerDidClickCellAtRow(nRow)   local i = nRow
   cclog("clicked:"..i) 
end
--将listview层的触摸打开
function setTouch_openLayer(layer)
    layer:registerScriptTouchHandler(onTouch_openLayer,nil,-129,nil)
    layer:setIsTouchEnabled(true)
end
--具体显示什么内容,每一页的内容
function testListView_triggerCellForRow(listview,data)
    m_nCurrnetPage = data.nRow + 1   --data.nRow从0开始
    local cell = CCListViewCell:node()
    cell:setOpacity(0)
    cell:setContentSize(m_pList:getContentSize())
    cell:setSelectionColor(ccc4(0, 0, 0, 0))
    data.cell = cell
    _curCell = cell
    local listItemSize = CCSize:new(m_pList:getContentSize().width , m_pList:getContentSize().height)
    for n = 1, data.nNumberOfRows do       
    cell:addChild(xxxxxx)
    end 
end

三、listview的使用

listview_layer = create_listview()
_layer:addChild(listview_layer,2)
setTouch_openLayer(listview_layer)
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics