Dynamic view heights in ScrollView with SDK 2.0.1

You must Login before you can answer or comment on any questions.

Probably, this isn't an unknown issue but I wasn't able to find anything helpful in the Q&A's.

I have an ScrollView with contentHeight:'auto' and two child views in it that also have an 'auto' height.

The following example code works fine when building it with Titanium SDK 1.8.0

var win = Titanium.UI.createWindow({backgroundColor:'#fff'});
 
var scrollView = Ti.UI.createScrollView({
    top:0,
    contentHeight:'auto',
    contentWidth:320,
    showVerticalScrollIndicator:true
});
 
var label_one = Ti.UI.createLabel({
    text: "Label One",
    top: 10,
    height: 'auto'
});
scrollView.add(label_one);
 
var label_two = Ti.UI.createLabel({
    text: "Label Two",
    top: label_one.top + label_one.height,
    height: 'auto'
});
scrollView.add(label_two);
 
win.add(scrollView);
win.open();
With Titanium SDK 2.X.X it doesn't behave the same way. I tried using height: Ti.UI.SIZE for the labels height properties and contentHeight: Ti.UI.FILL for the ScrollView but it didn't change the layout.

Does anybody know the best way to update the code to work with newest SDK? Thanks

— asked 7 months ago by Manuel Lehner
1 Comment
  • I really can't figure out how I should set the top-value of the second label to position it below the first label.

    — commented 7 months ago by Manuel Lehner

2 Answers

Try using width and height in your scroll view code.

var scrollView = Ti.UI.createScrollView({
    top:0,
    contentHeight:'auto',
    contentWidth:320,
    showVerticalScrollIndicator:true
});
should be used like
var scrollView = Ti.UI.createScrollView({
    top:0,
    height:Ti.UI.FILL,
    width:320,
    showVerticalScrollIndicator:true
});

— answered 7 months ago by Ashish Nigam
answer permalink
1 Comment
  • Thanks for your answer. But this change has no effect. The lable-views are still layered at the same position, even when they have Ti.UI.SIZE as their height-value.

    — commented 7 months ago by Manuel Lehner

OK, I finally found a solution that works for me:

I added the property layout: 'vertical' to the scrollview and set every label to top: 10

Now, the the labels are vertically alinged in the scrollview, no matter how high they are!

Your Answer

This question has been locked and cannot accept new answers.