Titanium Community Questions & Answer Archive

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

iPhone/Android: Better solution than absolute positioning?

What's a good way to position items in a window/view?

For example, I'm trying to put together a simple form with multiple input fields. Most of the code I found uses absolute positioning (left: 10, top:40). That doesn't seem very portable - android already has multiple screen sizes, and iPhone/iPad seems headed that way.

Are there css-like floats? Or other mechanisms for positioning things in a way that responds well to multiple orientations or screen sizes?

— asked August 24th 2010 by Parand Darugar
  • mobile
0 Comments

1 Answer

  • You can use horizontal and vertical layouts like this:

    var container = Titanium.UI.createView({
        layout: 'vertical'
    });
    
    var input_1 = Titanium.UI.createTextField({
        top: 10,
        left: 10,
        width: 300,
        height: 24
    });
    container.add(input_1);
    
    var input_2 = Titanium.UI.createTextField({
        top: 10,
        left: 10,
        width: 300,
        height: 24
    });
    container.add(input_2);
    

    The inputs will now be positioned underneath each other.

    — answered August 25th 2010 by Richard Venneman
    permalink
    1 Comment
    • Thanks, been trying to figure this out for an hour now >.<

      — commented September 10th 2010 by Shiki Shiji
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.