Titanium Community Questions & Answer Archive

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

Set view to phone width and height

I've made a simple view. Its just a box. Can I set the width and height to the phones width and height? I tried 'auto' but if I do that nothing shows up.

— asked October 11th 2010 by Ronnie Swietek
  • auto
  • height
  • view
  • width
0 Comments

7 Answers

  • I don't know why I didn't mention this before but you can pin the view by setting all 4 sides to 0.

    var view = Ti.UI.createView({backgroundColor: '#f00', left: 0, top: 0, right: 0, bottom: 0});
    
    — answered October 11th 2010 by John McKnight
    permalink
    3 Comments
    • -nod-

      — commented October 11th 2010 by Fred Spencer
    • I'd like to get one of those badges next to my name :-)

      — commented October 12th 2010 by John McKnight
    • OMG! This totally blew my mind. I've been setting positions everywhere, and on orientation detecting sizes for Android and sh1t.. This just saved my life!
      Thanks John

      — commented June 12th 2011 by Daniel Tome
  • Do you have a root window and the view added to it?

    — answered October 11th 2010 by John McKnight
    permalink
    0 Comments
  • Have you tried height: '100%', width: '100%'

    — answered October 11th 2010 by John McKnight
    permalink
    0 Comments
  • Fred,

    Unless I am mistaken this would work well provided the device started and remained in a specific orientation. If the device orientation changes, you'd need to hook the orientationchange event and change the height and width to match the new orientation.

    — answered October 11th 2010 by John McKnight
    permalink
    2 Comments
    • Correct. :-)

      — commented October 11th 2010 by Fred Spencer
    • "you'd need to hook the orientationchange event and change the height and width to match the new orientation." => how do i implement this?

      — commented March 23rd 2011 by Sandra Vandevoordt
  • yeah I first have my app.js file.

    Then from that I added my login.js file and I am in that window.

    Inside login.js, I did:
    var win = Titanium.UI.currentWindow;

    //made myView

    win.add(myView);

    — answered October 11th 2010 by Ronnie Swietek
    permalink
    0 Comments
  • 100% did the trick

    — answered October 12th 2010 by Ronnie Swietek
    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.