local LISTVIEW_WIDTH = 340 local LISTVIEW_HEIGHT = 405 local listView = ccui.ListView:create() -- set list view ex direction listView:setDirection(ccui.ScrollViewDir.vertical) listView:setBounceEnabled(true) -- listView:setBackGroundImage("hall/di.png") -- listView:setBackGroundImageScale9Enabled(true) listView:setContentSize(cc.size(LISTVIEW_WIDTH, LISTVIEW_HEIGHT)) listView:setAnchorPoint(cc.p(0, 0)) listView:setPosition(cc.p(10, 12)) listView:addEventListener(listViewEvent) -- SCISSOR listView:setClippingType(1) parent:addChild(listView)
localfunctioncreateDefaultListItem() local leaderboardItemLayer = cc.CSLoader:createNode("hall/LeaderboardItem.csb") -- retrieve the widget. MUST be a widget local listItemRoot = leaderboardItemLayer:getChildByTag(2001) listItemRoot:removeFromParent()
local listItemRootSize = listItemRoot:getContentSize() listItemRoot:setPosition(cc.p(LISTVIEW_WIDTH / 2.0, listItemRootSize.height / 2.0))
local default_item = ccui.Layout:create() default_item:setTouchEnabled(true) default_item:setContentSize(listItemRootSize) default_item:addChild(listItemRoot)
return default_item end
local default_item = createDefaultListItem() listView:setItemModel(default_item)
for i = 1, 100do listView:pushBackDefaultItem() end
-- set all items layout gravity listView:setGravity(ccui.ListViewGravity.centerVertical)