有没有人知道如何在使用英特尔XDK创建的Android应用中将屏幕方向锁定为肖像?
我放弃了,在最后3次尝试之后我发布了整个html文档,也许你可以弄清楚我做错了什么:
的index.html
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<script src="cordova.js"></script>
<script src="xhr.js"></script>
<script src="js/app.js"></script>
<script src="js/init-app.js"></script>
<script src="xdk/init-dev.js"></script>
<script src="intelxdk.js"></script>
<script>
document.addEventListener("intel.xdk.device.ready", onDeviceReady, false);
function onDeviceReady(){
intel.xdk.device.setRotateOrientation('portrait');
intel.xdk.device.hideSplashScreen();
}
</script>
<style>
@-ms-viewport { width: 100vw ; zoom: 100% ; }
@viewport { width: 100vw ; zoom: 100% ; }
@-ms-viewport { user-zoom: fixed ; }
@viewport { user-zoom: fixed ; }
</style>
<link rel="stylesheet" href="css/app.css">
</head>
<body>
<h1 class="align-center">Testing orientation lock</h1>
<p class="align-center">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec malesuada risus libero, nec consectetur nunc vestibulum quis. Nam rhoncus ullamcorper dui, vitae imperdiet augue vulputate non. In non sodales dolor. Maecenas sagittis, erat a consequat sollicitudin, enim metus feugiat sem, vel varius mauris eros vitae sapien. Vestibulum sollicitudin arcu eleifend augue feugiat sagittis a non arcu. Duis tempus laoreet faucibus. Morbi fermentum placerat lacus et consectetur. Aenean convallis diam in congue convallis. Ut at ullamcorper mauris. Fusce suscipit tincidunt lacus, et volutpat arcu bibendum eu. In vehicula mi lorem, eget vestibulum orci cursus ac. Etiam vitae quam ut ipsum accumsan viverra. Proin commodo augue diam, tincidunt pretium purus interdum et. Suspendisse tristique vehicula tempus. Praesent ultrices nibh et tortor venenatis, at laoreet augue sodales.
</p>
</body>
</html>
我已经尝试将以下内容添加到我的head标签中,但它没有工作......:
<script type="text/javascript" language="javascript">
function onDeviceReady() {
AppMobi.device.hideSplashScreen();
//lock orientation
AppMobi.device.setRotateOrientation("portrait");
AppMobi.device.setAutoRotate(false);
};
document.addEventListener("appMobi.device.ready",onDeviceReady,false);
function openNewWindow(url){
AppMobi.device.showRemoteSiteExt(url);
};
</script>
更新
我还尝试在intelxdk.config.additions.xml
中添加以下内容:
<preference name="Orientation" value="portrait" />
..它没有工作......
更新2
我也尝试过:
<script src="intelxdk.js"></script>
<script>
document.addEventListener("intel.xdk.device.ready", onDeviceReady, false);
function onDeviceReady(){
// set orientation
intel.xdk.device.setRotateOrientation('portrait');
intel.xdk.device.hideSplashScreen();
}
</script>
答案 0 :(得分:1)
请按照以下步骤操作:
添加
android:screenOrientation="portrait"
到你的AndroidManifest.xml。
它应该看起来像这样:
<activity android:screenOrientation="portrait" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/app_name" android:name="inappbrowser" android:theme="@android:style/Theme.Black.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
否则总会有this个插件。
答案 1 :(得分:0)
尝试了我能找到并想到的一切后,我最终使用了this(GitHub链接)插件。
下载GitHub存档。
将 plugin.xml 和 src 文件夹复制到根文件中。
复制 screenorientation.android.js , screenorientation.bb10.js , screenorientation.ios.js 和 screenorientation.js < / strong>到 www 文件夹。
将以下内容添加到 index.html head :
中<script>
screen.lockOrientation('landscape');
</script>
...如果需要,您可以将风景更改为人像。