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)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值