0

我在 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

4

1 回答 1

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

这是给定代码的结果

于 2013-06-13T11:54:48.097 回答