Allen Gingrich
Allen Gingrich

Reputation: 5657

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.

Upvotes: 8

Views: 9460

Answers (2)

Brian
Brian

Reputation: 16206

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>

Upvotes: 22

gary
gary

Reputation: 4255

May be a duplicate question, but yes, here's one way to do it:

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

Upvotes: 6

Related Questions