This scrollView is going to high - why?

Hello,

I added this scrollView to my landscape view app and it scrolls to the top of the screen. I set the top/left. What do I do to show this list in onlty part of the screen rather than the whole thing? I didn’t think it would scroll above 60 which is the top that I set.

Thanks

 scrollView = widget.newScrollView{ top = 60, left = 10, width = 400, height = 200, scrollWidth = 400, scrollHeight = 600 } scrollView:setReferencePoint(display.TopLeftReferencePoint) local y2 = 100 local fonts = native.getFontNames() local count, found\_count = 0, 0 for i,fontname in ipairs(fonts) do print("found font: " .. fontname) local obj = display.newText(fontname, 0, 0, fontname, 24) obj:setReferencePoint(display.TopLeftReferencePoint) obj:setTextColor(0, 0, 0) y2 = y2 + 30 obj.x = 5 obj.y = y2 scrollView:insert(obj) end grpFont:insert(scrollView)

Hi Warren,

Scrollviews and tableviews that don’t occupy the entire screen must be masked to their constrained region, as described in the documentation. Or, you can wait for the roll-out of Graphics 2.0 widgets which will support containers for auto-masking.

Best regards,

Brent

Thanks. That fixed the problem and I can scroll trough all of the fonts in the simulator. When I run on my Android it only lets me scroll through the first few. The scroll bar on the right is all the way down to the button but I can tell there are more font names in the scrollView. What would be stopping the scroll?

Below is my code:

local grpFont = display.newGroup() grpFont.isVisible = true local function scrollListener( event ) local phase = event.phase local direction = event.direction local obj = event.target -- local reference to button if "began" == phase then obj.timer = system.getTimer() --print( "Began" ) elseif "moved" == phase then --print( "Moved" ) elseif "ended" == phase then local t = system.getTimer() -- get the current time local df = t - obj.timer -- calc time the finger was held down if df \> 1000 then -- if finger held on object for more than a second -- DO SOMETHING local alert = native.showAlert( "Corona", "Dream. Build. Ship.", { "OK", "Learn More" }) end end -- If we have reached one of the scrollViews limits if event.limitReached then if "up" == direction then --print( "Reached Top Limit" ) elseif "down" == direction then --print( "Reached Bottom Limit" ) elseif "left" == direction then --print( "Reached Left Limit" ) elseif "right" == direction then --print( "Reached Right Limit" ) end end return true end local scrollView -- Touch event listener for background image local function onSceneTouch( event ) print( "onSceneTouch ", event.phase ) print( imgHome.ready ) if event.phase == "ended" then elseif event.phase == "moved" then -- Check if you moved your finger while touching local dx = math.abs( event.x - event.xStart ) -- Get the x-transition of the touch-input local dy = math.abs( event.y - event.yStart ) -- Get the y-transition of the touch-input if dx \> 5 or dy \> 5 then scrollView:takeFocus( event ) -- If the x- or y-transition is more than 5 put the focus to your scrollview end end return true end scrollView = widget.newScrollView{ top = 120, left = 10, width = 400, height = 200, scrollWidth = 400, scrollHeight = 800, maskFile = "images/maskfont.png", listener = scrollListener } scrollView:setReferencePoint(display.TopLeftReferencePoint) local y2 = 100 local fonts = native.getFontNames() local count, found\_count = 0, 0 for i,fontname in ipairs(fonts) do print("found font: " .. fontname) local obj = display.newText(fontname, 0, 0, fontname, 24) obj:setReferencePoint(display.TopLeftReferencePoint) obj:setTextColor(0, 0, 0) y2 = y2 + 30 obj.x = 5 obj.y = y2 scrollView:insert(obj) end grpFont:insert(scrollView)

Hi Warren,

Since you’re reading the system fonts, there will be a variance between platforms. But, it looks like you’re setting the same “scrollHeight” for the widget, but that should be calculated (multiplied out) based on the number of fonts in the view.

Brent

Thanks for the reply. I increased the scrollHeight to 1800 and still the same. It scrolls most of them but the last few do not show. Can someone show how to scroll the fonts in a scrollView control?

The list starts down low showing only a couple and seems like it stops that way with a few not showing.

Hi Warren,

Scrollviews and tableviews that don’t occupy the entire screen must be masked to their constrained region, as described in the documentation. Or, you can wait for the roll-out of Graphics 2.0 widgets which will support containers for auto-masking.

Best regards,

Brent

Thanks. That fixed the problem and I can scroll trough all of the fonts in the simulator. When I run on my Android it only lets me scroll through the first few. The scroll bar on the right is all the way down to the button but I can tell there are more font names in the scrollView. What would be stopping the scroll?

Below is my code:

local grpFont = display.newGroup() grpFont.isVisible = true local function scrollListener( event ) local phase = event.phase local direction = event.direction local obj = event.target -- local reference to button if "began" == phase then obj.timer = system.getTimer() --print( "Began" ) elseif "moved" == phase then --print( "Moved" ) elseif "ended" == phase then local t = system.getTimer() -- get the current time local df = t - obj.timer -- calc time the finger was held down if df \> 1000 then -- if finger held on object for more than a second -- DO SOMETHING local alert = native.showAlert( "Corona", "Dream. Build. Ship.", { "OK", "Learn More" }) end end -- If we have reached one of the scrollViews limits if event.limitReached then if "up" == direction then --print( "Reached Top Limit" ) elseif "down" == direction then --print( "Reached Bottom Limit" ) elseif "left" == direction then --print( "Reached Left Limit" ) elseif "right" == direction then --print( "Reached Right Limit" ) end end return true end local scrollView -- Touch event listener for background image local function onSceneTouch( event ) print( "onSceneTouch ", event.phase ) print( imgHome.ready ) if event.phase == "ended" then elseif event.phase == "moved" then -- Check if you moved your finger while touching local dx = math.abs( event.x - event.xStart ) -- Get the x-transition of the touch-input local dy = math.abs( event.y - event.yStart ) -- Get the y-transition of the touch-input if dx \> 5 or dy \> 5 then scrollView:takeFocus( event ) -- If the x- or y-transition is more than 5 put the focus to your scrollview end end return true end scrollView = widget.newScrollView{ top = 120, left = 10, width = 400, height = 200, scrollWidth = 400, scrollHeight = 800, maskFile = "images/maskfont.png", listener = scrollListener } scrollView:setReferencePoint(display.TopLeftReferencePoint) local y2 = 100 local fonts = native.getFontNames() local count, found\_count = 0, 0 for i,fontname in ipairs(fonts) do print("found font: " .. fontname) local obj = display.newText(fontname, 0, 0, fontname, 24) obj:setReferencePoint(display.TopLeftReferencePoint) obj:setTextColor(0, 0, 0) y2 = y2 + 30 obj.x = 5 obj.y = y2 scrollView:insert(obj) end grpFont:insert(scrollView)

Hi Warren,

Since you’re reading the system fonts, there will be a variance between platforms. But, it looks like you’re setting the same “scrollHeight” for the widget, but that should be calculated (multiplied out) based on the number of fonts in the view.

Brent

Thanks for the reply. I increased the scrollHeight to 1800 and still the same. It scrolls most of them but the last few do not show. Can someone show how to scroll the fonts in a scrollView control?

The list starts down low showing only a couple and seems like it stops that way with a few not showing.