Titanium Community Questions & Answer Archive

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

Controlling the layout of Elements

I have some general layout questions that I think will be useful for everyone:

  1. Is there anyway to have elements in a view stack on top of each other automatically. This would be useful if you don't know how tall a block of text in a label is going to be and you want another item to always be below it.

  2. is there anyway to get elements to line up next to each other automatically. This is nice if you have a list of labels that need to show up one after another and the length and number of labels is unknown.

So far it seems everything has to be positioned absolutely. I appreciate any help you can offer. Thanks.

— asked March 29th 2010 by Alex Wolfe
  • layout
0 Comments

2 Answers

  • Accepted Answer

    You can solve your first problem by adding layout:'vertical' to your view and height:'auto' to each of the objects added to the view, using top to specify a margin to act as padding between the objects.

    See, eg, vertical_layout_basic.js and vertical_layout_table_view.js.

    I'm afraid I'm not sure what you mean by the second question. You can use width:'auto' and set left and right margins if you want to ensure the edges of the objects line up vertically.

    — answered March 29th 2010 by James K
    permalink
    1 Comment
    • I know this is old, but this doesn't work in Android. Only iPhone. I just wasted my time, and I hope it helps someone that sees this.

      — commented July 3rd 2011 by Daniel Tome
  • If you are using Webview, you can use CSS.

    If not, I think you can labels, tables, views and set height and width, font, font sizes, etc. to get what you want.

    — answered March 29th 2010 by Peter Lum
    permalink
    0 Comments
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.