Android - Vertical layout only


Android Problem Overview

How do I make sure my app is only for vertical layout?

I have tried android:screenOrientation="portrait" but that doesn't seem to do the trick.

Android Solutions

Solution 1 - Android

You need to add to all your activity not for one only. I think you understood that setting is per application wide, but it isn't.

<activity android:name=".MyActivity"
          android:label="My Activity"

Add the declaration to the activity tag in AndroidManifest for every Activity you want to be portrait-only.

Solution 2 - Android

If you want some group of your activities to be locked on PORTRAIT mode only, than you can choose the next way:

public abstract class BasePortraitActivity extends Activity {
    protected final void onCreate(Bundle state) {

    protected abstract void performOnCreate(Bundle state);


And than just extend BasePortraitActivity where you need it. Or just add setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); to YourActivity.onCreate().

Solution 3 - Android

you have to change into AndroidManifest.xml.

for each activity you have to insert:

android:configChanges = "orientation"

android:screenOrientation = "portrait"

for e.g.:

<activity android:name=".YourActivityName"
                  android:configChanges = "orientation"
                  android:screenOrientation = "portrait">

This works for a single activity.. But there seems no application wide setting there.

Solution 4 - Android

In your manifest under activity add this :


Solution 5 - Android

Activity is to block just in case want to block all and only repeat this line of code in their Activitys.

protected void onCreate(Bundle savedInstanceState) {

    // Here, talk to the java does not want that the user can rotate their activity.


or open your "AndroidManisfest.xml" and add the rows for the portrait mode as shown below.


Solution 6 - Android

Add android:configChanges="keyboardHidden|orientation" to the activity.

Solution 7 - Android

Just to confirm Pentium10's answer.
I was having a similar issue and adding android:screenOrientation="portrait" to the activity tag.
Did the trick for me.

Solution 8 - Android

Put this attribute in layout root:


It may help.


All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionteepusinkView Question on Stackoverflow
Solution 1 - AndroidPentium10View Answer on Stackoverflow
Solution 2 - AndroidddmytrenkoView Answer on Stackoverflow
Solution 3 - AndroidSameer KulkarniView Answer on Stackoverflow
Solution 4 - AndroidZeusView Answer on Stackoverflow
Solution 5 - AndroidMichel SilvaView Answer on Stackoverflow
Solution 6 - AndroidChrisView Answer on Stackoverflow
Solution 7 - AndroidBillView Answer on Stackoverflow
Solution 8 - AndroidKanteshView Answer on Stackoverflow