插入小部件按钮后,滚动视图不会滚动

时间:2015-11-20 13:10:47

标签: view scroll lua scrollview corona

我正在制作我们的顶级项目,它用于灾难准备,但我的问题是这个滚动视图在放置小部件标签后不会滚动。它在放置按钮之前滚动。我使用小部件按钮,使它看起来像这样。

Layout

代码:

local storyboard = require( "storyboard" )
local scene = storyboard.newScene()

local widget = require "widget"

function scene:createScene( event )
    local group = self.view 

    background = display.newImage("ehead.png", true)
    background.x = 360
    background.y = 150
    group:insert(background)

    local function onBackbuttonRelease()    
            storyboard.gotoScene( "mainmenu", "slideRight", 200)
            return true
    end


    local Backbutton = widget.newButton
    {
        defaultFile = "back.png",
        overFile = "back2.png",
        onRelease = onBackbuttonRelease
    }
    Backbutton.x = 45 ; Backbutton.y = 105
    group:insert( Backbutton )

local scrollView = widget.newScrollView
{
    top = 180,
    left = 6,
    width = display.contentWidth,
    height = display.contentHeight,
    scrollWidth = display.contentWidth,
    scrollHeight = 8000
}
group:insert(scrollView)
local options = {
    text = "",
    width = 700,
    font = "HelveticaNeue",
    fontSize = 50,
    align = "center"
}

    local altavas= widget.newButton
    {
        defaultFile = "al.png",
        overFile = "al2.png",
        onRelease = onaltavasRelease
    }
    altavas.x = 354; altavas.y = 70
    scrollView:insert( altavas )

    local balete= widget.newButton
    {
        defaultFile = "ba.png",
        overFile = "ba2.png",
        onRelease = onbaleteRelease
    }
    balete.x = 354; balete.y = 190
    scrollView:insert( balete )

    local banga= widget.newButton
    {
        defaultFile = "ban.png",
        overFile = "ban2.png",
        onRelease = onbangaRelease
    }
    banga.x = 354; banga.y = 310
    scrollView:insert( banga )

    local buruanga = widget.newButton
    {
        defaultFile = "bu.png",
        overFile = "bu2.png",
        onRelease = onburuangaRelease
    }
    buruanga.x = 354; buruanga.y = 430
    scrollView:insert( buruanga )

    local ibajay = widget.newButton
    {
        defaultFile = "ib.png",
        overFile = "ib2.png",
        onRelease = onibajayRelease
    }
    ibajay.x = 354; ibajay.y = 550
    scrollView:insert( ibajay )

    local kalibo = widget.newButton
    {
        defaultFile = "ka.png",
        overFile = "ka2.png",
        onRelease = onkaliboRelease
    }
    kalibo.x = 354; kalibo.y = 670
    scrollView:insert( kalibo )

    local lezo = widget.newButton
    {
        defaultFile = "le.png",
        overFile = "le2.png",
        onRelease = onlezoRelease
    }
    lezo.x = 354; lezo.y = 790
    scrollView:insert( lezo )

    local libacao = widget.newButton
    {
        defaultFile = "li.png",
        overFile = "li2.png",
        onRelease = onlibacaoRelease
    }
    libacao.x = 354; libacao.y = 910
    scrollView:insert( libacao )

    local madalag = widget.newButton
    {
        defaultFile = "ma.png",
        overFile = "ma2.png",
        onRelease = onmadalagRelease
    }
    madalag.x = 354; madalag.y = 1030
    scrollView:insert( madalag )

    local makato = widget.newButton
    {
        defaultFile = "mak.png",
        overFile = "mak2.png",
        onRelease = onmakatoRelease
    }
    makato.x = 354; makato.y = 1150
    scrollView:insert( makato )

    local malay = widget.newButton
    {
        defaultFile = "mal.png",
        overFile = "mal2.png",
        onRelease = onmalayRelease
    }
    malay.x = 354; malay.y = 1270
    scrollView:insert( malay )

    local malinao = widget.newButton
    {
        defaultFile = "mali.png",
        overFile = "mali2.png",
        onRelease = onmalinaoRelease
    }
    malinao.x = 354; malinao.y = 1390
    scrollView:insert( malinao )

    local nabas = widget.newButton
    {
        defaultFile = "na.png",
        overFile = "na2.png",
        onRelease = onnabasRelease
    }
    nabas.x = 354; nabas.y = 1510
    scrollView:insert( nabas )

    local nw = widget.newButton
    {
        defaultFile = "nw.png",
        overFile = "nw2.png",
        onRelease = onnwRelease
    }
    nw.x = 354; nw.y = 1630
    scrollView:insert( nw )

    local numancia = widget.newButton
    {
        defaultFile = "nu.png",
        overFile = "nu2.png",
        onRelease = onnumanciaRelease
    }
    numancia.x = 354; numancia.y = 1750
    scrollView:insert( numancia )

    local tangalan = widget.newButton
    {
        defaultFile = "ta.png",
        overFile = "ta2.png",
        onRelease = ontangalanRelease
    }
    tangalan.x = 354; tangalan.y = 1870
    scrollView:insert( tangalan )

end

scene:addEventListener( "createScene", scene )

return scene

1 个答案:

答案 0 :(得分:0)

这很简单,只需使用:https://docs.coronalabs.com/api/type/ScrollViewWidget/takeFocus.html

但我鼓励你制作自定义按钮,而不是使用widget.newButton。

但如果您仍然喜欢使用widget.newButton,请看一下: https://forums.coronalabs.com/topic/42033-widget-button-inside-a-scrollview-doesnt-work-when-i-use-the-takefocus-method/