CodeMonkey
CodeMonkey

Reputation: 12424

Android ScreenOrientation behavior

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.

Upvotes: 2

Views: 624

Answers (2)

hrskrs
hrskrs

Reputation: 4480

Force it dynamically:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

Upvotes: 1

Ravi K Thapliyal
Ravi K Thapliyal

Reputation: 51711

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.

Upvotes: 3

Related Questions