2013-06-12 102 views
0

我在Corona的GridView中顯示圖像,但我不知道GridView爲什麼不滾動。請大家幫我怎麼做?我main.lua文件的代碼和屏幕截圖如下所示Corona的Gridview不滾動

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 

enter image description here

我已經使用這個鏈接,所以這樣做https://github.com/worldstar/GridView-for-Corona-SDK

回答

0

,我已經使用滾動視圖控件在Corona顯示圖像像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 

This is result of the given code

+1

在風只是一個刺,但基於代碼,你已經證明你沒有設置scrollwidth和scrollHeight屬性。你需要設置這兩個,因爲它們都是必需的。這決定了你的滾動視圖的大小。當我第一次使用scrollview時,我遇到了同樣的問題。我只是設置寬度和高度,它的工作。這裏是滾動視圖的文檔:http://docs.coronalabs.com/api/library/widget/newScrollView.html – user1597438

+0

哦,右邊的朋友其實我也是新來的電暈和盧阿:) –

+0

嗯,祝你好運你的項目。希望我幫助。 :)保持編碼! – user1597438