2

I got an activity which I want to always remain with portrait layout. I got these settings in the manifest file:

<activity android:name="Main"
            android:launchMode="singleInstance"
            android:label="@string/app_name" android:screenOrientation="portrait" android:configChanges="keyboardHidden|orientation" android:windowSoftInputMode="stateAlwaysHidden|adjustNothing">

This settings makes the activity just load the portrait layout to the side if I turn the device on the side. I want the layout to just remain in the portrait position and that's it even though it means viewing the layout on the side when switching the device 90 degrees.

CodeMonkey
  • 11,196
  • 30
  • 112
  • 203
  • Already answered here :: https://stackoverflow.com/questions/582185/android-disable-landscape-mode?rq=1 – Harsh Feb 12 '15 at 14:37

2 Answers2

3

From Android 3.2 onwards, you also need to add screenSize to configChanges

android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize"

From the developer docs at handling runtime changes

Caution: Beginning with Android 3.2 (API level 13), the "screen size" also changes when the device switches between portrait and landscape orientation.

Ravi K Thapliyal
  • 51,095
  • 9
  • 76
  • 89
1

Force it dynamically:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

hrskrs
  • 4,447
  • 5
  • 38
  • 52