Android 安装应用程序后屏幕\u方向\u纵向不工作

Android 安装应用程序后屏幕\u方向\u纵向不工作,android,android-layout,android-studio,android-fragments,Android,Android Layout,Android Studio,Android Fragments,在纵向模式下锁定应用程序的方向时出现问题。我将android:screenOrientation=“trait”和android:configChanges=“orientation”添加到我的清单中。此外,我在我的main活动的onCreate(…)中添加了setRequestedOrientation(ActivityInfo.SCREEN\u ORIENTATION\u crative)。main活动由AppCompatActivity扩展。在任何时候,它都可以工作,所以你永远不会看到你的

在纵向模式下锁定应用程序的方向时出现问题。我将
android:screenOrientation=“trait”
android:configChanges=“orientation”
添加到我的清单中。此外,我在我的
main活动的
onCreate(…)
中添加了
setRequestedOrientation(ActivityInfo.SCREEN\u ORIENTATION\u crative)
main活动
AppCompatActivity
扩展。在任何时候,它都可以工作,所以你永远不会看到你的应用是横向的,除非你第一次在你的设备上安装它。然后可以在横向和纵向方向之间切换。有人知道为什么会这样吗?先谢谢你

不要将方向应用于application元素,而是应该将属性应用于activity元素,并且还必须设置configChanges,如下所述

例如:

<activity
   android:screenOrientation="portrait"
   android:configChanges="orientation|keyboardHidden">
</activity>


这在
清单
文件AndroidManifest.xml中应用。

remove-config-changes-propert-of-activity-from-manifest