Search code examples
androidiostitaniumtitanium-mobile

achieve same layout on android & iOS Titanium


i'm creating an ios,android app using titanium so i positioning my ui view on specific percentage from screen size using platformWidth and platformHeight multiplied by a number e.g. 0.5*platformHeight for the middle of the screen and every thing work on all iOS devices sizes.
but on android devices this value became too large

Note i m using "dp" as a default unit 

so any idea on how to achieve same layout in this way


Solution

  • You can actually use percentage as value of position properties. ex top : '40%'. This percentage is calculated wrt parent. And if you don't specify any position by default the view will be positioned in centre of the parent unless, parent is a vertical or horizontal layout.

    Also are you specifying the default unit as below?

    <property name="ti.ui.defaultunit">dp</property>
    

    If this is the case then here's what might be happening. Say the device height is 800px. Halving it give 400 px. This is the value you are expecting. But when you assign this value again to the view it is converted to DP. So, it turns out to be 400 x device density, which will be greater than 400 for sure. To overcome this you might have to assign the property something like top: 0.5*platformHeight+'px'. I'm not sure if this trick will work as I do not have the setup to test it.