Scrollview positioning objects inside. Issues with using contentCenterX and contentCenterY

Hi,

I’m having some fun with positioning objects inside of a scroll view.  I am trying to do a ‘setttings’ type screen with several sub groups of settings each with its own rounded rectangle as a background and then having the relevant settings within that i.e. sounds -> music on/off etc

My problem is I have fallen at the first hurdle which is just trying to get my sub group centered in the scrollview.  Even though it should be centered horizontally it doesnt seem to work.  If i duplicate the exact same code outside of the scroll view it positions as I’d expect.

Is there some gotcha with the scroll view I have not read about?  I have gone through all the doco’s and searched for people with similar issues but cant come up with anything… The only thing left is that i have done something stupid that I just can’t see! 

 One workaround I suppose is to stick all the objects in to the scrollview and then ‘offset’ the scroll view to make sure its contents are centered - this doesnt feel like a great solution though.  

I’d be very grateful if somebody could take a look and explain to me why this is happening and how best to resolve it.

Im wondering if its some odd cross over from moving to graphics 2.0 and the change to how anchor points work?

Thanks so much :slight_smile:

-- Create the widget local scrollView = widget.newScrollView { width = 250, height = 300, scrollHeight = 800, horizontalScrollDisabled = true } scrollView.x = display.contentCenterX scrollView.y = display.contentCenterY -- Create object and insert it into the scroll view local tmpGrp = display.newGroup( ) local subGrp = display.newRoundedRect(tmpGrp, 0, 0, 150 , 150, 10) subGrp.x = display.contentCenterX subGrp.y = display.contentCenterY subGrp:setFillColor( 0, 1, 1 ) scrollView:insert( tmpGrp ) local subGrp = display.newRoundedRect(0, 0, 150 , 150, 10) subGrp.x = display.contentCenterX subGrp.y = display.contentCenterY subGrp:setFillColor( 1, 0, 0 ) --scrollView:insert( subGrp )

Should probably mention im using this config.lua:  

local aspectRatio = display.pixelHeight / display.pixelWidth application = { content = { width = aspectRatio \> 1.5 and 320 or math.ceil( 480 / aspectRatio ), height = aspectRatio \< 1.5 and 480 or math.ceil( 320 \* aspectRatio ), scale = "letterBox", fps = 60, imageSuffix = { ["@2x"] = 1.5, ["@4x"] = 3.0, }, },

Nevermind… it seems to take the postion relative to the scroll view so I just need to use the width of the scrollview / 2 rather than contentCenterX

Should probably mention im using this config.lua:  

local aspectRatio = display.pixelHeight / display.pixelWidth application = { content = { width = aspectRatio \> 1.5 and 320 or math.ceil( 480 / aspectRatio ), height = aspectRatio \< 1.5 and 480 or math.ceil( 320 \* aspectRatio ), scale = "letterBox", fps = 60, imageSuffix = { ["@2x"] = 1.5, ["@4x"] = 3.0, }, },

Nevermind… it seems to take the postion relative to the scroll view so I just need to use the width of the scrollview / 2 rather than contentCenterX