The issue i’m having is that when I create a scroll bar feature my content and title seam to go out of line in the screen. The title is slightly off the screen at the top and the content is slightly out to the left and right. It looks like it has already been scrolled a tad down but when I try to scroll it back up it flicks back again. Not sure on how to go about this, I would also like it so that the page cannot scroll left or right I couldn’t work out how to make this happen. The code i’m currently using is…
[lua]
–
– home.lua
–
local composer = require( “composer” )
local scene = composer.newScene()
local widget = require( “widget” )
local function scrollListener( event )
local phase = event.phase
if ( phase == “began” ) then print( “Scroll view was touched” )
elseif ( phase == “moved” ) then print( “Scroll view was moved” )
elseif ( phase == “ended” ) then print( “Scroll view was released” )
end
– In the event a scroll limit is reached…
if ( event.limitReached ) then
if ( event.direction == “up” ) then print( “Reached top limit” )
elseif ( event.direction == “down” ) then print( “Reached bottom limit” )
elseif ( event.direction == “left” ) then print( “Reached left limit” )
elseif ( event.direction == “right” ) then print( “Reached right limit” )
end
end
return true
end
function scene:create( event )
local sceneGroup = self.view
– Called when the scene’s view does not exist.
–
– INSERT code here to initialize the scene
– e.g. add display objects to ‘sceneGroup’, add touch listeners, etc.
– ScrollView listener
– Create the widget
local scrollView = widget.newScrollView
{
top = 1,
left = 1,
width = 300,
height = 480,
scrollWidth = 310,
scrollHeight = 480,
listener = scrollListener
}
local bg = display.newRect( 0, 0, display.contentWidth, display.contentHeight )
bg.anchorX = 0
bg.anchorY = 0
bg:setFillColor( 1 ) – white
scrollView:insert( bg )
local title = display.newText( “Home”, 0, 0, native.systemFont, 32 )
title:setFillColor( 0 ) – black
title.x = display.contentWidth * 0.5
title.y = -10
scrollView:insert( title )
local contentText1 = display.newText( “Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!”, 170, 150, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 16 )
contentText1:setFillColor( 0, 0.5, 1 )
scrollView:insert( contentText1 )
local contentText2 = display.newText( “Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!”, 170, 400, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 16 )
contentText2:setFillColor( 0, 0.5, 1 )
scrollView:insert( contentText2 )
local contentText3 = display.newText( “Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!”, 170, 650, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 16 )
contentText3:setFillColor( 0, 0.5, 1 )
scrollView:insert( contentText3 )
sceneGroup:insert( scrollView )
end
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if phase == “will” then
– Called when the scene is still off screen and is about to move on screen
elseif phase == “did” then
– Called when the scene is now on screen
–
– INSERT code here to make the scene come alive
– e.g. start timers, begin animation, play audio, etc.
end
end
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if event.phase == “will” then
– Called when the scene is on screen and is about to move off screen
–
– INSERT code here to pause the scene
– e.g. stop timers, stop animation, unload sounds, etc.)
elseif phase == “did” then
– Called when the scene is now off screen
end
end
function scene:destroy( event )
local sceneGroup = self.view
– Called prior to the removal of scene’s “view” (sceneGroup)
–
– INSERT code here to cleanup the scene
– e.g. remove display objects, remove touch listeners, save state, etc.
end
– Listener setup
scene:addEventListener( “create”, scene )
scene:addEventListener( “show”, scene )
scene:addEventListener( “hide”, scene )
scene:addEventListener( “destroy”, scene )
return scene
[/lua]
Thanks again,
Matt.