ika*_*ita 1 appcelerator appcelerator-mobile appcelerator-titanium appcelerator-alloy
我即将使用appcelerator钛框架测试应用程序,我必须在屏幕上居中显示:
我的index.xml:
<Alloy>
<!-- Anddroid Window -->
<Window id="index" platform="android">
<Require type="view" id="firstscreen" src="firstscreen"/>
</Window>
<!-- iOS Window -->
<NavigationWindow id="nav" platform="ios">
<Window id="win1" backgroundColor="white">
<Require type="view" id="firstscreen" src="firstscreen"/>
</Window>
</NavigationWindow>
Run Code Online (Sandbox Code Playgroud)
第一个屏幕xml:
<Alloy>
<ScrollView scrollingEnabled="false" contentWidth="Ti.UI.FILL">
<ImageView class="fullBgImage" image="/images/login/bg2.png" />
<View layout="vertical">
<View id="loginView" class="heightAuto" layout="vertical">
<ImageView id="localImage" image="/images/logo.png" />
<Label class="logoLabel" text="Karma" />
<Label class="logoSlogan" text="Faits confiance à votre Karma pour booster votre carrière" />
<View class="btn btnVert" onClick="openCandidat"><Label class="btnLabel" text="Je recherche un job" /></View>
<View class="btn btnBlanc" ><Label class="btnLabel bleu" text="Je suis recruteur" /></View>
</View>
</View>
</ScrollView>
</Alloy>Run Code Online (Sandbox Code Playgroud)
index.js: 实现的公式是:viewTopPosition =(platformheight - viewheight)/ 2
if (OS_ANDROID) {
$.index.addEventListener('open', after_win_load);
$.index.open();
} else {
$.nav.addEventListener('open', after_win_load);
$.nav.open();
}
function after_win_load() {
// Platform height
var platformHeight = Ti.Platform.displayCaps.platformHeight;
// The view
var firstscreen = $.firstscreen;
/* Taille du logo */
firstscreenViewHeight = firstscreen.loginView.size;
/* Centrer la vue verticalement */
firstScreenTop = platformHeight - firstscreenViewHeight.height;
//firstscreen.top = firstScreenTop;
var style = $.createStyle({
classes : 'firstScreenTop',
apiName : 'View',
top : firstScreenTop / 2
});
firstscreen.loginView.applyProperties(style);
}Run Code Online (Sandbox Code Playgroud)
在iO上它看起来很棒,视图是垂直居中的,但在android中:Ti.Platform.displayCaps.platformHeight是一个太大的像素值= 1920
在我已经指定的tiapp.xml文件中:
<property name="ti.ui.defaultunit" type="string">dp</property>Run Code Online (Sandbox Code Playgroud)
我知道android是像素单位但iOs使用dp单位,所以我该如何实现这一点呢?有人有想法吗?对于现在的android我取代了
var platformHeight = Ti.Platform.displayCaps.platformHeight;Run Code Online (Sandbox Code Playgroud)
至
var platformHeight = Ti.Platform.displayCaps.dpi;Run Code Online (Sandbox Code Playgroud)
但我问自己是否对所有Android屏幕分辨率都有好处?如果这是最佳做法?
谢谢你的帮助.
var densityFactor = OS_IOS ? 1 : Ti.Platform.displayCaps.logicalDensityFactor;
var platformHeight = Ti.Platform.displayCaps.platformHeight / densityFactor;
Run Code Online (Sandbox Code Playgroud)
或者你可以直接将顶部设置为50%
var style = $.createStyle({
classes : 'firstScreenTop',
apiName : 'View',
top : "50%"
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
970 次 |
| 最近记录: |