如何将Android应用程序的方向锁定到纵向模式? [英] How to lock android app's orientation to portrait mode?

查看:102
本文介绍了如何将Android应用程序的方向锁定到纵向模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Android应用程序,当用户旋转设备时,我的方向不想更改为横向模式。此外,我希望锁定的方向是手机上的肖像模式和平板电脑的横向模式。这可以实现吗,如果是的话呢?谢谢。

I am developing an Android app whose orientation I don't want changed to landscape mode when the user rotates the device. Also, I want the locked orientation to be portrait mode on phones and landscape mode on tablets. Can this be achieved, if yes how? Thanks.

推荐答案

您只需在 AndroidManifest.xml 文件中的com / guide / topics / manifest / activity-element.htmlrel =noreferrer> activity 元素。它将限制您的朝向肖像。

You just have to define the property below inside the activity element in your AndroidManifest.xml file. It will restrict your orientation to portrait.


android:screenOrientation =portrait

android:screenOrientation="portrait"

示例:

        <activity
            android:name="com.example.demo_spinner.MainActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
        </activity>

另外,根据Eduard Luca的评论,您还可以使用 screenOrientation = sensorPortrait如果要启用旋转180度。

Additionaly, as per Eduard Luca's comment below, you can also use screenOrientation="sensorPortrait" if you want to enable rotation by 180 degrees.

这篇关于如何将Android应用程序的方向锁定到纵向模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆