所以,我在 Corona 中使用了 scrollView 小部件来显示像 Gridview 这样的图像,这是我的代码。
display.setStatusBar( display.DefaultStatusBar )
local widget = require( "widget" )
local scrollView = widget.newScrollView
{
--left = 0,
--top = 0,
--width = display.contentWidth,
--height = display.contentHeight,
id = "onBottom",
horizontalScrollDisabled = false,
verticalScrollDisabled = false,
listener = scrollListener,
}
local centerX_Row1 = 110
local centerX_Row2 = 110
local shows = {}
local length = 5;
function displayShow( event )
print( "Touch event began on: "..tostring(event.target[2].text))
![enter image description here][1]end
for k = 1,length,1 do
shows[k] = {}
shows[k].image_name = "assets/pic8.png"
shows[k].showname = "show "..k
end
for k = 1,#shows,2 do
--Row 1
local group = display.newGroup();
--local image = display.newImage( shows[k].image_name )
local image = display.newImageRect(shows[k].image_name,175,125)
local text = display.newText(shows[k].showname,-40, -60, native.systemFontBold, 24 )
group:insert(image)
group:insert(text)
group.x = centerX_Row1
group.y = 100
centerX_Row1 = centerX_Row1 + 190
group:addEventListener( "tap", displayShow)
scrollView:insert( group )
if(k+1 <= #shows) then
--Row 2
local group = display.newGroup();
--local image = display.newImage( shows[k+1].image_name )
local image = display.newImageRect(shows[k].image_name,175,125)
local text = display.newText(shows[k+1].showname, -40, -60, native.systemFontBold, 24 )
group:insert(image)
group:insert(text)
group:addEventListener( "tap", displayShow)
group.x = centerX_Row2
group.y = 240
centerX_Row2 = centerX_Row2 + 190
scrollView:insert( group )
end
end