2014年6月26日 星期四

Titanium App: Handle view size for different screen size of Android

1. Change the standard unit to dp (or dip, density-independent pixel).
    So that all view's width and height value are in dp, instead of default unit 'pixel'

    In tiapp.xml, add/change


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

    Note: default value for this property is 'system', which means 'pixel' on Android, 'dip' on iOS 


2. To calculate the screen size, divide screen width and height by density factor:

Screen width:
Ti.Platform.displayCaps.platformWidth / Ti.Platform.displayCaps.logicalDensityFactor

Screen height:
Ti.Platform.displayCaps.platformHeight / Ti.Platform.displayCaps.logicalDensityFactor

沒有留言:

張貼留言