Use percent in titanium for liquids / reactive design

In any case, if you use the Titanium Appcelerator to use Percentages. For fluid and responsive design; otherwise it seems that I will fight with IF ELSE instructions for all devices!

Original code

    WebViewWindow=Titanium.UI.createWebView({
    html:globalHTMLHeadert,
    visible:true,
    width:100%, //note I have tried also "100%" with/out comma
    left:0,
    bottom:30%,
    zIndex:400
});

I want to

WebViewWindow=Titanium.UI.createWebView({
    html:globalHTMLHeadert,
    visible:true,
    width:320,
    left:0,
    bottom:150,
    zIndex:400
});
+3
source share
2 answers

Simple

Create a new file called frames.js

/*
 * Frames
 * @ We uses this framework to allow mobility for responsive design
 * @ Each variable is used and this is the width based on the device
 */
// 100%
var per100 = Math.floor(Titanium.Platform.displayCaps.platformWidth * 1.0); 
// 90%
var per90 = Math.floor(Titanium.Platform.displayCaps.platformWidth * 0.9); 
// 80%
var per80 = Math.floor(Titanium.Platform.displayCaps.platformWidth * 0.8); 
// 50%
var per50 = Math.floor(Titanium.Platform.displayCaps.platformWidth * 0.5); 
// 40%
var per40 = Math.floor(Titanium.Platform.displayCaps.platformWidth * 0.4);
// 25%
var per25 = Math.floor(Titanium.Platform.displayCaps.platformWidth * 0.25); 
// 10%
var per10 = Math.floor(Titanium.Platform.displayCaps.platformWidth * 0.10); 
// 5%
var per5 = Math.floor(Titanium.Platform.displayCaps.platformWidth * 0.05); 
// 1%
var per1 = Math.floor(Titanium.Platform.displayCaps.platformWidth * 0.01);

Now include frames.js in js files.

You can use it as such, it will be a liquid button, 90%

var btngeorgia=Titanium.UI.createButton({
    color:'#d8d8d8',
    borderRadius:'2px',
    height:30,
    width:per90,
    zIndex:800,
    left:10,
    bottom:100,
    title:'Georgia',
    font:'Georgia',
});

This will be a 100% web view of the deviceโ€™s fluid width.

WebViewWindow=Titanium.UI.createWebView({
    html:globalHTMLHeadert,
    visible:true,
    width:per100,
    left:0,
    bottom:220,
    zIndex:300
});
+6
source

All Articles