小编Cuồ*_*Yết的帖子

在AndroidManifest.xml中设置screenOrientation不起作用

我有一个简单的hello world Android测试项目.在我的AndroidManifest.xml中,我已经设置好了

android:screenOrientation="portrait" 
android:configChanges="keyboardHidden|keyboard|orientation">
Run Code Online (Sandbox Code Playgroud)

但是当我调试我的代码时,变量isLandscape是真的,它应该是假的

boolean isLandscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
Run Code Online (Sandbox Code Playgroud)

我知道我也可以通过代码设置活动方向,但出于某些原因我需要在xml中设置它.我该怎么做?

编辑:我的AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.androidgames.mreater"
android:versionCode="1"
android:versionName="1.0" 
android:installLocation="preferExternal">

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<application
    android:icon="@drawable/ic_launcher"
    android:allowBackup="true"
    android:label="Mr. Eater" >
    <activity
        android:name="com.androidgames.mreater.MrEaterGame"
        android:label="Mr. Eater" 
        android:screenOrientation="portrait"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
Run Code Online (Sandbox Code Playgroud)

我的实际onCreate活动方法:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    boolean isLandscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    int frameBufferWidth = isLandscape ? 480 : 320;
    int frameBufferHeight = isLandscape …
Run Code Online (Sandbox Code Playgroud)

xml android orientation landscape-portrait android-activity

6
推荐指数
2
解决办法
2万
查看次数