如何将Android App的方向锁定为手机中的人像和平板电脑中的风景? [英] How to Lock Android App's Orientation to Portrait in Phones and Landscape in Tablets?

查看:95
本文介绍了如何将Android App的方向锁定为手机中的人像和平板电脑中的风景?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个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.

推荐答案

您只需在

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 =肖像"

android:screenOrientation="portrait"

示例:

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

此外,根据下面爱德华·卢卡(Eduard Luca)的评论,如果要启用180度旋转,也可以使用screenOrientation="sensorPortrait".

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

这篇关于如何将Android App的方向锁定为手机中的人像和平板电脑中的风景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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