我在Corona的GridView中显示图像,但我不知道为什么GridView不滚动。请大家帮我怎么做?我的main.lua文件代码和截图如下所示
display.setStatusBar( display.DefaultStatusBar )
local widget = require( "widget" )
local gridView = require("gridView")
local photoArray ={"assets/pic1.png","assets/pic1.png","assets/pic2.png","assets/pic3.png","assets/pic4.png","assets/pic5.png","assets/pic5.png"}
local photoTextArray = {"pic7","pic1","pic2","pic3","pic4","pic5 Long Text Test","pic6"}
gridView:new(25, 50, photoArray, photoTextArray, 2, 10, 20,150, 150, gridListener)
local function gridListener(index)
print("You select item "..index)
end
我已使用此链接执行此操作https://github.com/worldstar/GridView-for-Corona-SDK
答案 0 :(得分:0)
所以,我在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