强制 Phonegap(Android)启动画面方向

6
我在我的PhoneGap应用程序中添加了一个启动画面,方法是在DefaultActivitysuper.loadURL...行之前添加super.setIntegerProperty("splashscreen", R.drawable.splash);代码。

有没有办法只锁定启动画面的方向为纵向而不锁定整个应用程序?

5个回答

5

经过多次搜索,我发现正确处理启动屏幕方向的方法是使用以下代码在您的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");
    }

4
以下解决方案适用于Cordova 3+在Android和iOS上。它仅锁定启动画面的方向,然后在应用程序运行时解锁方向。
在config.xml中修复方向:
<preference name="orientation" value="portrait" />

在应用程序初始化后,使用此屏幕方向插件来解锁它:

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

1
如果你正在使用最新版本的PhoneGap(DroidGap)或Apache Cordova,你可以通过更改Android.xml文件中的screenOrientation来强制屏幕方向为横向。得到的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>

7
这是否会将整个应用程序的屏幕方向锁定为横向?原问题是关于将启动画面方向锁定为竖向,同时不锁定整个应用程序的屏幕方向。 - Yoh Suzuki

0
在你的AndroidManifest.xml文件中添加这行代码:
<activity android:name="SplashScreen" android:screenOrientation="portrait"></activity> 

0
在启动屏幕活动的onCreate方法中编写以下内容:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);


谢谢,但问题在于使用 Phonegap 时,启动画面不是一个独立的活动。如果我将方向强制应用于该活动,则整个应用程序都会被强制。 - user992804

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接