简体   繁体   English

如何在Android中锁定手机方向以防止横向模式

[英]How to lock phone orientation in Android to prevent landscape mode

Is this possible to do? 这可能吗? Landscape mode distorts the background image, and therefore I would like to lock orientation to vertical on phones with accelerometers. 横向模式会扭曲背景图像,因此我想在具有加速度计的手机上将方向锁定为垂直方向。

Thanks. 谢谢。

You can force the screen orientation to always be portrait for individual activities in the manifest . 您可以强制屏幕方向始终为清单中各个活动的纵向。 You use the 你用的是

android:screenOrientation

attribute with the value "portrait" in each of the activities you want to always have the portrait orientation. 在您希望始终具有纵向方向的每个活动中具有值“portrait”的属性。

<activity android:name=".MyActivity" android:screenOrientation="portrait">
...
</activity>

May be a duplicate question, but yes, here's one way to do it: 可能是一个重复的问题,但是,是的,这是一种方法:

// This forces a vertical screen.
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM