即使在禁用活动后,活动的方向仍在变化

时间:2016-02-05 07:56:45

标签: android screen-orientation

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/Theme.Fantasy">

        <activity
            android:name="view.StandingsActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:configChanges="keyboardHidden|orientation|screenSize">
        </activity>

        <activity
            android:name="view.LoginActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:configChanges="keyboardHidden|orientation|screenSize">    
        </activity>

        <activity
            android:name="view.RegisterActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:configChanges="keyboardHidden|orientation|screenSize">    
        </activity>

        <activity
            android:name="view.PlayerStandingsActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:configChanges="keyboardHidden|orientation|screenSize">    
        </activity>

        <activity
            android:name="view.ScheduleActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:configChanges="keyboardHidden|orientation|screenSize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name="view.MatchStatsActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:configChanges="keyboardHidden|orientation|screenSize">    
        </activity>

        <activity
            android:name="view.PlayerDetailsActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:configChanges="keyboardHidden|orientation|screenSize">    
        </activity>

        <activity
            android:name="view.PlayerStatsActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:configChanges="keyboardHidden|orientation|screenSize">
            </activity>

        <activity
            android:name="view.AwardsActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:configChanges="keyboardHidden|orientation|screenSize">
        </activity>

        <activity
            android:name="view.TeamActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:configChanges="keyboardHidden|orientation|screenSize">
        </activity>

        <activity
            android:name="view.AddPlayersActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:configChanges="keyboardHidden|orientation|screenSize">
        </activity>

    </application>

这是我的清单文件的一部分。我已指定禁用横向模式,但在旋转屏幕时仍然会更改方向。我错过了什么?我必须在这里添加任何权限吗?

2 个答案:

答案 0 :(得分:2)

你可以覆盖每个活动的onConfigurationChanged方法来自己处理方向更改。另外在清单文件中声明android:configChanges你根本无法处理它们。

@Override 
public void onConfigurationChanged(Configuration newConfig) {
   super.onConfigurationChanged(newConfig);
   setRequestedOrientation(ActivityInfo."orientation type your preffer");
} 

答案 1 :(得分:1)

android:screenOrientation="portrait" or "landscape"文件中设置manifest时,如果您想要执行此操作,则不会触发侦听器尝试以编程方式处理您的onConfigurationChanged()中的仅限肖像模式,此处您也将是能够再次开始活动。

结帐Documentation on OrientationListener