开发者

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 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜