简体   繁体   中英

Scroll view doesn't scroll after inserting widget buttons

I'm making our capstone project, its for disaster preparedness, but my problem is this scroll view wont scroll after placing widget tabs. It scrolled before placing the buttons. I use widget buttons so that it will look like this.

布局

Code:

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

This is quite simple just use: https://docs.coronalabs.com/api/type/ScrollViewWidget/takeFocus.html

but I encourage You to make custom buttons instead of using widget.newButton.

But if You still prefer to use widget.newButton take a look here: https://forums.coronalabs.com/topic/42033-widget-button-inside-a-scrollview-doesnt-work-when-i-use-the-takefocus-method/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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