我如何禁用景观模式的一些观点在我的Android应用程序?


当前回答

只需在活动标记中添加此属性。

 android:screenOrientation="portrait"

其他回答

你应该在AndroidManifest.xml中修改android:screenOrientation="sensorPortrait

在Activity的onCreate()中使用

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

在<apphome>/platform/android目录下,创建AndroidManifest.xml(从生成的目录中复制它)。

然后添加android:screenOrientation="portrait"到所有的活动元素。

如果您正在使用Xamarin c#,其中一些解决方案将无法工作。这是我发现的一个有效的解决方案。

[Activity(MainLauncher = true, Icon = "@drawable/icon", ScreenOrientation = ScreenOrientation.Portrait)]

上面的类工作得很好,类似于其他解决方案。此外,它不是全局适用的,需要放在每个活动头中。

在阅读这篇文章之前,我不知道AndroidManifest.xml文件开关,所以在我的应用程序中,我使用了这个代替:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // Fixed portrait orientation