2012-03-07 101 views
5

我通过添加“super.setIntegerProperty(”splashscreen“,R.drawable.splash);”在DefaultActivity中的super.loadURL ...行之前。强制Phonegap(Android)启动屏幕方向

有没有办法只锁定启动屏幕的方向肖像,而不锁定整个应用程序?

回答

1

如果您使用的是最新的PhoneGap(DroidGap)或Apache科尔多瓦的版本通过在Android更改screenOrientation可以强制屏幕方向为横向。 xml文件。得到的DroidGap“实例活动”应该是这个样子:

 <activity 
     android:name="org.apache.cordova.DroidGap" 
     android:label="@string/app_name" 
     android:configChanges="orientation|keyboardHidden" 
     android:screenOrientation="landscape"   
     > 
     <intent-filter> 
     </intent-filter> 
    </activity> 
+6

这不会将整个应用程序的方向锁定为横向吗?原始问题是关于将启动画面方向锁定到肖像,而不锁定整个应用程序的方向。 – 2012-07-12 19:36:32

0

写溅射屏幕活动的onCreate方法内执行以下操作:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

+0

谢谢,但问题是与PhoneGap的,在启动画面不是一个单独的活动。如果我强迫这个活动的方向,我会强制整个应用程序。 – user992804 2012-03-07 08:25:51

0

在AndroidManifest.xml中添加这一行:

4

许多搜索后,我发现,解决闪屏方向的正确方法是管理使用此代码两个图像到您的MainActivity

if (getResources().getConfiguration().orientation == 2) { 
     super.setIntegerProperty("splashscreen", R.drawable.splashlandscape); 
     Log.d("Orientation", "Landscape"); 
    } 
    else { 
     super.setIntegerProperty("splashscreen", R.drawable.splashportrait); 
     Log.d("Orientation", "Portrait"); 
    } 
+0

这工作。谢谢 !!! – Rajaraman 2013-05-31 06:33:16

5

以下解决方案适用于Android和iOS上的Cordova 3+。它只锁定闪屏的方向,然后在应用程序运行后解锁。

固定取向config.xml中:

<preference name="orientation" value="portrait" /> 

然后用这个screen orientation plugin来解锁一次应用程序已初始化:

document.addEventListener("deviceready", function(){ 
    screen.unlockOrientation(); 
}, false); 
+0

谢谢!奇迹般有效! – Lotus 2016-02-01 14:44:39