开发者

How to lock phone orientation in Android to prevent landscape mode

开发者 https://www.devze.com 2023-01-14 04:41 出处:网络
Is this possible to do? Landscape mode distorts the background image, and therefore I woul开发者_运维百科d like to lock orientation to vertical on phones with accelerometers.

Is this possible to do? Landscape mode distorts the background image, and therefore I woul开发者_运维百科d 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.

<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);
0

精彩评论

暂无评论...
验证码 换一张
取 消