Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/181.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在AndroidManifest.xml中设置屏幕方向无效_Android_Xml_Android Activity_Orientation_Landscape Portrait - Fatal编程技术网

在AndroidManifest.xml中设置屏幕方向无效

在AndroidManifest.xml中设置屏幕方向无效,android,xml,android-activity,orientation,landscape-portrait,Android,Xml,Android Activity,Orientation,Landscape Portrait,我有一个简单的hello world Android测试项目。在我的AndroidManifest.xml中,我已经设置了 android:screenOrientation="portrait" android:configChanges="keyboardHidden|keyboard|orientation"> 但是,当我调试代码时,变量isLandscape应该是False,而变量isLandscape应该是True boolean isLandscape = getResou

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

android:screenOrientation="portrait" 
android:configChanges="keyboardHidden|keyboard|orientation">
但是,当我调试代码时,变量isLandscape应该是False,而变量isLandscape应该是True

boolean isLandscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
我知道我也可以通过代码设置活动方向,但出于某些原因,我需要在xml中设置它。我怎么做

编辑:my 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>

现在变得更奇怪了,isLandscape变量是真的,但有时是假的。这有点像一只虫子。

除了一件事之外,一切似乎都很好!我不知道这是否是你的情况,但你应该读一下:D

如果应用程序的API级别为13或更高,则必须声明
screeSize

如果应用程序的目标API级别为13或更高(如 minSdkVersion和targetSdkVersion属性),那么您还应该 声明“屏幕大小”配置,因为当 设备在纵向和横向之间切换


让我知道这可以解决您的问题。

请确保将其放入

vs


您将需要为您在
清单.xml中定义的每个
活动
设置它。屏幕方向是否实际更改,或者只是变量返回true?您在活动标记上设置的是否正确?不把它放在应用程序标签中?活动屏幕是横向的,不是我想要的纵向的。@KenWolf是的。我在活动标签中设置了它。@Cuồ纽约ế这并不奇怪。我只是尝试了一下,但无法复制这个问题。所有设备/模拟器上都存在这个问题?谢谢Ken Wolf,但我把它放在了活动标记中,而不是应用程序标记中。我不知道它是什么,从您描述的内容来看,一切都很好。也许可以编辑您的帖子并添加您的
manifest.xml
?我们需要更多线索:)@Cuồ纽约ết、 如果您声明的目标API为13或更高,您也必须声明
screeSize
。我想到的另一件事(很长时间)-确保没有其他错误阻止您构建应用程序,并且您实际上正在测试应用程序的最新版本。对字符串或其他东西做一个小改动,看看能不能通过。谢谢yugidroid。我的应用程序目标API级别为17。我添加了“屏幕大小”配置,但它不起作用。活动仍在进行中。
@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 ? 320 : 480;
   Bitmap frameBuffer = Bitmap.createBitmap(frameBufferWidth,
            frameBufferHeight, Config.RGB_565);

    float scaleX = (float) frameBufferWidth
            / getWindowManager().getDefaultDisplay().getWidth();
    float scaleY = (float) frameBufferHeight
            / getWindowManager().getDefaultDisplay().getHeight();

    renderView = new AndroidFastRenderView(this, frameBuffer);
    graphics = new AndroidGraphics(getAssets(), frameBuffer);
    fileIO = new AndroidFileIO(getAssets());
    audio = new AndroidAudio(this);
    input = new AndroidInput(this, renderView, scaleX, scaleY);
    screen = this.getStartScreen();
   setContentView(renderView);

    PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "GLGame");
}