You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AndroidManifest配置屏幕方向无效果,强制应用仅横屏模式运行失败求助

问题原因及解决方案

嘿,我一眼就发现问题所在啦!你的AndroidManifest.xml里的Activity标签存在XML语法错误,导致横屏配置完全没有被系统识别,所以布局一直保持竖屏状态。

错误点分析

你把android:screenOrientation和android:configChanges这两个属性单独写在了<activity>起始标签的外面,这不符合XML的语法规范——标签的属性必须嵌套在起始标签的尖括号内部,而不能作为独立的行存在。系统会把这些单独的属性行当成无效的子元素,自然不会应用横屏配置。

修正后的AndroidManifest代码

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.nikhiljain.canvasdrawingsample">
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.CanvasDrawingSample">
        <activity 
            android:name=".MainActivity"
            android:screenOrientation="landscape"
            android:configChanges="orientation|keyboardHidden">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

验证方法

修正代码后,重新运行你的项目(或者重启模拟器),此时应用会默认以横屏模式启动,并且旋转模拟器时也会保持横屏状态,完全符合你的需求。

内容的提问来源于stack exchange,提问作者VanessaF

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 15:34:07