Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Position relative to previous element

Hi all,

Is it possible to position an element relative to the previous one?

I have to labels, and there should be a 15px space between them, but the problem is, the length of the text in the first label can be anything from one line to 20 lines, so I can't set a fixed offset for the second label, and only have the 15px space between them.

Is there any workaround the handle this?

Kind Regards
Daniel

— asked October 15th 2010 by Daniel Juhl Mogensen
  • element
  • iphone
  • label
  • mobile
  • position
  • views
0 Comments

4 Answers

  • try adding

    layout:'vertical' property to the window…

    and for every element that you add just keep the "top:15" ……

    Guess this should do the trick….

    — answered October 18th 2010 by Satta Ravi
    permalink
    0 Comments
  • This type of solution worked for me:

    var top = 0;
    
    var label1 = Ti.UI.createLabel({
        text: 'text',
        height: 'auto',
        top: top + 15
    });
    
    top = label1.top + label1.height;
    
    var label2 = Ti.UI.createLabel({
        text: 'text',
        height: 'auto',
        top: top + 15
    });
    
    top = label2.top + label2.height;
    
    //...
    
    — answered October 15th 2010 by Charles Davison
    permalink
    0 Comments
  • Actually Sattanaathan is right, but you can also set this property layout:'vertical' to view, and it's work for me as well.

    — answered April 26th 2012 by Pierre Lesigne
    permalink
    0 Comments
  • Best option I can think of is to use a view for each element with the end of the first of beginning of the second element have a 15px top, left, etc.. definition as needed. Add both of those views to another Scroll view with a vertical or horizontal layout defined. The ScrollView will automatically handle alignment of it's children (views) and then the elements in those views will be aligned with a 15px difference.

    I hope that makes sense…

    — answered October 15th 2010 by Brian Raymond
    permalink
    1 Comment
    • It sounds to be a solution, but how to get the ending of the element? If height is set to auto it returns nothing afterwards, at least for labels. Is this different for views?

      — commented October 15th 2010 by Daniel Juhl Mogensen
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.