发布时间: 2015-02-03 11:38:00
官方文档给出的答案是:(refer to: http://docs.appcelerator.com/titanium/3.0/#!/guide/Alloy_Styles_and_Themes-section-35621526_AlloyStylesandThemes-Platform-SpecificStyles
1. 先定义好全局变量,在系统加载的时候:
app/alloy.js Alloy.Globals.isIos7Plus = (OS_IOS && parseInt(Ti.Platform.version.split(".")[0]) >= 7); Alloy.Globals.iPhoneTall = (OS_IOS && Ti.Platform.osname == "iphone" && Ti.Platform.displayCaps.platformHeight == 568);
2. 然后针对不同的机器,定义不同的tss
// Query styles "#info[if=Alloy.Globals.isIos7Plus]" : { font : { textStyle : Ti.UI.TEXT_STYLE_FOOTNOTE } }, "#title[if=Alloy.Globals.isIos7Plus]" : { top: '25dp', // compensate for the status bar on iOS 7 font : { textStyle : Ti.UI.TEXT_STYLE_HEADLINE } }, "#content[if=Alloy.Globals.isIos7Plus]" : { font : { textStyle : Ti.UI.TEXT_STYLE_CAPTION1 } }, "ScrollView[if=Alloy.Globals.iPhoneTall]" : { height : '500dp' }
另外,如果不看官方文档,我搜到的结果如下:
refer to http://stackoverflow.com/questions/7326632/titanium-handling-different-resoutions
and: http://developer.appcelerator.com/question/159770/do-we-have-any-conditions-to-handle-in-xml-file#comment-195451,
(这个主意看答案下面的最后一个注释。。。,给出了上面的链接)http://developer.appcelerator.com/question/159946/how-to-support-different-resolutions-in-titanuim-alloy-xml
基本上是两种观点:
1. 使用dp 作为安卓系统的单位
2. 对于不同的 屏幕,使用不同的XML (在XML 中嵌入 if 语句)
其实我的观点是,能否像 native android的官方文档那样,不同的XML 放到对应的 layout-sw600dp, layout-sw720dp 目录下?
res/layout/main_activity.xml # For handsets (smaller than 600dp available width) res/layout-sw600dp/main_activity.xml # For 7” tablets (600dp wide and bigger) res/layout-sw720dp/main_activity.xml # For 10” tablets (720dp wide and bigger)
结论是不能。 因为 Titanium的工作原理是,把 XML 转换成 javascript ,再转换成 java/ios code. 无法像 原生的android那样,直接调用XML 文件。
可惜了。
refer to: http://docs.appcelerator.com/titanium/latest/#!/guide/Using_density-specific_resources_on_Android
Back