Position relative to previous element

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

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

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....

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;
 
//...

Actually Sattanaathan is right, but you can also set this property layout:'vertical' to view, and it's work for me as well.

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 3 years ago by Brian Raymond
answer 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 3 years ago by Daniel Juhl Mogensen

Your Answer

Think you can help? Login to answer this question!