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

來源:互聯網
上載者:User

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 = truelayer: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)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.