加载远程图像并添加到滚动视图

时间:2013-12-09 16:50:04

标签: scrollview corona

我正在从URL加载图像,我试图让它出现在我的滚动视图中,但似乎只在主视图上打印它。有没有办法告诉它在滚动视图上打印?

这是我正在使用的代码:

rowImg = display.loadRemoteImage("http://www.newyorker.com/online/blogs/photobooth/NASAEarth-01.jpg", "GET", networkListener, "banner.png",system.TemporaryDirectory,  (globalData.contentX * rows2) + globalData.contentX/2, 20 + (i - 1) % 6 * 140)   

1 个答案:

答案 0 :(得分:4)

您可以按照以下方式执行此操作:

local widget = require( "widget" )

local scrollView = widget.newScrollView{
    width = display.contentWidth,
    height = display.contentHeight,
    scrollWidth = 0,
    scrollHeight = 0,
    horizontalScrollDisabled = true,
    hideBackground = true
}
localGroup:insert(scrollView)


local function networkListener( event )
        if ( event.isError ) then
                print ( "Network error - download failed" )
        else
                event.target.alpha = 0
                transition.to( event.target, { alpha = 1.0 } )
                scrollView:insert(event.target)  -- This will add your remote image to the scroll view
        end
end
display.loadRemoteImage( "http://www.newyorker.com/online/blogs/photobooth/NASAEarth-01.jpg", "GET", networkListener, "helloCopy.png", system.TemporaryDirectory, 0, 0 )

保持编码............:)

相关问题