繁体   English   中英

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

[英]Scroll view doesn't scroll after inserting widget buttons

我正在制作我们的顶点项目,它是为了备灾,但我的问题是这个滚动视图在放置小部件选项卡后不会滚动。 它在放置按钮之前滚动。 我使用小部件按钮,使其看起来像这样。

布局

代码:

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

这很简单,只需使用: 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方法/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM