Titanium Community Questions & Answer Archive

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

Problem with view widths in Android emulator

Having a bit of an issue and hope you guys can help me out, here.

I have a window with the width set to ''100%'. Inside that window, I've added views (usingcreateView) width widths set to'50%'`.

The visual effect I'm trying to acheive is that the views take up one side of the screen.

Instead this is what I get: Screenshot

It seems to only happen on Android (emulator and device), but not on the iPhone.

Any idea what's going on?

— asked July 28th 2010 by Alexander Stone
  • android
  • createview
  • design
  • layout
  • ui
  • width

1 Answer

  • This is an old question, I realize. However, we discovered this weekend that the Android SDK does not handle percentages. You'll need to set an absolute width and height.

    — answered February 20th 2011 by Thomas Cottrill
    • Android handles percent as of 1.5.0

      — commented February 23rd 2011 by Don Thorp
    • Sorry. Meant to type 1.6.0.

      — commented February 23rd 2011 by Don Thorp
    • You can use Tim Poulsen's workaround:

      var width = Math.round(Ti.Platform.displayCaps.platformWidth*0.9); // 90%
      var height = Math.round(Ti.Platform.displayCaps.platformHeight*0.9); // 90%

      Source: Titanium Q&A

      Also, there is a ticket made for this issue here.

      — commented April 1st 2011 by Joe iEntry
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.