Cannot set scrollView's Height

Hi

I used the ScrollView sample code from Corona installation, and I found I cannot fixed the hegith of ScrollViewl

The following source is same as Corona default installation, and I just set backgroup color to see what happend for the height of Scrollview after I set height=display.contentHeight*0.5.

display.setDefault( “background”, 0,255, 0 )
display.setStatusBar( display.HiddenStatusBar )
local widget = require( “widget” )
 
local scrollView = widget.newScrollView
{
    left = 0,
    top = 0,
    width = display.contentWidth,
     height = display.contentHeight*0.5 ,
    bottomPadding = 50,
    id = “onBottom”,
    horizontalScrollDisabled = true,
    verticalScrollDisabled = false,
    listener = scrollListener,
}

–Create a large text string
local lotsOfText = "Lorem ipsum dolor sit amet, …  "

–Create a text object containing the large text string and insert it into the scrollView
local lotsOfTextObject = display.newText( lotsOfText, 0, 0, 300, 0, “Helvetica”, 14)
lotsOfTextObject:setTextColor( 0 )
lotsOfTextObject:setReferencePoint( display.TopCenterReferencePoint )
lotsOfTextObject.x = display.contentCenterX
lotsOfTextObject.y = titleText.y + titleText.contentHeight + 10
scrollView:insert( lotsOfTextObject )

The screen result is as following pic:

The above source code set the background color of screen is green and the background color of screen is white.

And you can find even I set _ height = display.contentHeight*0.5, _ actually the text out of scrollview is still in the screen (green area).

How to set exactly scrollview size thus the text is only shown in scrollview area ?

Thanks

You need to create a bitmap mask, and apply that onto the scrollview:

http://www.coronalabs.com/blog/2012/05/29/how-to-use-bitmap-masks/

Also see the “Gotchas” section here:

http://docs.coronalabs.com/api/library/widget/newScrollView.html

It’s annoying, I would much rather that it was able to automask based on the height + width we supply, but for now this is the only way to have non-fullscreen scrollviews / tableviews (as far as I know - feel free to correct me if I’m wrong).

Thanks for your help.

Yes, setMask is workable, but not so convenient. We have to make different pre-defined mask bitmap file for different app if we don’t use same resolution.

The best way to do this is as you mentioned, an automask function based on the height + width. Looking forward Corona next update for this function.

Another suggestion, Corona also may create a new TextBox widget component which can put a very long string into that TextBox, then add this TextBox into a scrollView.

There’s a new blog post about ‘containers’ which seem to be auto-masking display groups. They’re part of graphics 2.0, hopefully they’ll work with scroll views too. Not an immediate fix, but hopefully not too far away now.

That new blog post looks great and which is exactly what I am looking for. Hope it can be released as soon as posibile.

Thanks for your great information.

You need to create a bitmap mask, and apply that onto the scrollview:

http://www.coronalabs.com/blog/2012/05/29/how-to-use-bitmap-masks/

Also see the “Gotchas” section here:

http://docs.coronalabs.com/api/library/widget/newScrollView.html

It’s annoying, I would much rather that it was able to automask based on the height + width we supply, but for now this is the only way to have non-fullscreen scrollviews / tableviews (as far as I know - feel free to correct me if I’m wrong).

Thanks for your help.

Yes, setMask is workable, but not so convenient. We have to make different pre-defined mask bitmap file for different app if we don’t use same resolution.

The best way to do this is as you mentioned, an automask function based on the height + width. Looking forward Corona next update for this function.

Another suggestion, Corona also may create a new TextBox widget component which can put a very long string into that TextBox, then add this TextBox into a scrollView.

There’s a new blog post about ‘containers’ which seem to be auto-masking display groups. They’re part of graphics 2.0, hopefully they’ll work with scroll views too. Not an immediate fix, but hopefully not too far away now.

That new blog post looks great and which is exactly what I am looking for. Hope it can be released as soon as posibile.

Thanks for your great information.