Created
September 25, 2012 12:24
-
-
Save mogya/3781468 to your computer and use it in GitHub Desktop.
An idea to convert dp to/from pixel on TitaniumMobile Android
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// convert dp to pixel. | |
function dpToPixel(dp) { | |
return ( parseInt(dp) * (Titanium.Platform.displayCaps.dpi / 160)); | |
} | |
// convert pixel to dp. | |
function pixelToDp(px) { | |
return ( parseInt(px) / (Titanium.Platform.displayCaps.dpi / 160))+'dp'; | |
} | |
Ti.API.debug('dpToPixel test 100px:'+dpToPixel('100dp')); | |
Ti.API.debug('dpToPixel test s:100:'+dpToPixel('100')); | |
Ti.API.debug('dpToPixel test i:100:'+dpToPixel(100)); | |
Ti.API.debug('pixelToDp test 100px:'+pixelToDp('100px')); | |
Ti.API.debug('pixelToDp test s:100:'+pixelToDp('100')); | |
Ti.API.debug('pixelToDp test i:100:'+pixelToDp(100)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment