Alp*_*App 4 mobile titanium appcelerator responsive-design
无论如何使用Titanium Appcelerator来使用百分比.用于流体和响应设计; 否则看起来我会为所有设备的IF ELSE语句而烦恼!
原始代码
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
});
Run Code Online (Sandbox Code Playgroud)
我想要
WebViewWindow=Titanium.UI.createWebView({
html:globalHTMLHeadert,
visible:true,
width:320,
left:0,
bottom:150,
zIndex:400
});
Run Code Online (Sandbox Code Playgroud)
简单.
创建一个名为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);
Run Code Online (Sandbox Code Playgroud)
现在,在js文件中包含frames.js.
你可以这样使用它,这将是一个流畅的按钮,90%
var btngeorgia=Titanium.UI.createButton({
color:'#d8d8d8',
borderRadius:'2px',
height:30,
width:per90,
zIndex:800,
left:10,
bottom:100,
title:'Georgia',
font:'Georgia',
});
Run Code Online (Sandbox Code Playgroud)
这将是100%流体设备宽度的Web视图
WebViewWindow=Titanium.UI.createWebView({
html:globalHTMLHeadert,
visible:true,
width:per100,
left:0,
bottom:220,
zIndex:300
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4463 次 |
| 最近记录: |