I’m using Appcelerator mobile, and have a window with a vertical layout. The window contains an arbitrary number of stacked labels containing arbitrary text of various lengths. The total text may exceed the size of the window, and roll off the bottom of the screen.
I’d like to make the window scrollable, vertically, so the the user can continue reading to the end of the text. What is the best way to do this? Unless I’m missing it, KitchenSink doesn’t demonstrate anything like this. I don’t know the height of the various label, as it may vary from invocation to invocation, so absolute positioning won’t work (or at least not easily).
I’m tempted to see if I can just stick it in a table.
My existing code looks something like this:
var win =Ti.UI.createWindow({layout: "vertical"});
win.add(Ti.UI.createLabel({text: "long text here", height: "auto"});
win.add(Ti.UI.createLabel({text: "more long text here", height: "auto"});
win.add(Ti.UI.createLabel({text: "even more long text here", height: "auto"});
What you want to do is add a ScrollView (use Ti.UI.createScrollView) to your window and add your labels to that ScrollView.
Documentation for the ScrollView object is here: http://developer.appcelerator.com/apidoc/mobile/1.0/Titanium.UI.ScrollView