Search code examples
androidviewwidthtitanium-mobile

How can I convert width in percentage to a number value?


I'm creating a view with width = 20%. how can i get an integer value of that.

var v = Ti.UI.createView({
    width: '20%',
    left: '10%',
    height: '40%',
    top: '10%'
});

I need to convert v.width to digits. How can i do that?


Solution

  • Please try this:

    var screenWidth = Titanium.Platform.displayCaps.platformWidth;
    
    var v = Ti.UI.createView({
       width: screenWidth/5 ,
       left: '10%',
       height: '40%',
       top: '10%'
    });