-
-
Save thecfguy/89c666f0ba5b0eb48f33 to your computer and use it in GitHub Desktop.
Arrange labels for all kind of density
This file contains 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
function dpToPixel(dp) { | |
return ( parseInt(dp) * (Titanium.Platform.displayCaps.dpi / 160)); | |
} | |
// convert pixel to dp. | |
function pixelToDp(px,nounit) { | |
return ( parseInt(px) / (Titanium.Platform.displayCaps.dpi / 160)) + (nounit?0:'dp'); | |
} | |
var reArrangeLable = function(){ | |
var screenwidth = pixelToDp($.vw.toImage().width,true); | |
var screenheight = pixelToDp($.vw.toImage().height,true); | |
Ti.API.info([screenwidth,screenheight]); | |
$.lefttop.top = 0; | |
$.lefttop.left = 0; | |
$.righttop.top = 0; | |
$.righttop.left = (screenwidth -$.righttop.width - 20) + 'dp'; | |
$.center.top = (screenheight/2 - $.center.height/2) + 'dp'; | |
$.center.left = pixelToDp(Ti.Platform.displayCaps.platformWidth/2,true)-($.center.width/2) + 'dp'; | |
$.leftbottom.top = screenheight - $.leftbottom.height; | |
$.leftbottom.left = 0; | |
$.rightbottom.top = screenheight - $.rightbottom.height; | |
$.rightbottom.left = (screenwidth -$.rightbottom.width) + 'dp'; | |
}; | |
Ti.Gesture.addEventListener('orientationchange',function(e) { | |
setTimeout(reArrangeLable,1000); | |
}); | |
$.index.open(); | |
setTimeout(reArrangeLable,1000); |
This file contains 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
<Alloy> | |
<Window class="container"> | |
<View id="vw"> | |
<Label id="lefttop" onClick="doClick" backgroundColor="#12ef43">lefttop</Label> | |
<Label id="righttop" onClick="doClick" backgroundColor="#ff1243">righttop</Label> | |
<Label id="leftbottom" onClick="doClick" backgroundColor="#12ef43">leftbottom</Label> | |
<Label id="rightbottom" onClick="doClick" backgroundColor="#ff1243">rightbottom</Label> | |
<Label id="center" onClick="doClick" backgroundColor="#ff1243">center</Label> | |
</View> | |
</Window> | |
</Alloy> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment