Midhun Kumar
Midhun Kumar

Reputation: 577

Setting Landscape orientation in phones using setRequestedOrientation

When setting landscape orientation in an android apps activity using setRequestedOrientation the activity first comes up in portrait and then goes into landscape in phones. The setRequestedOrientaiton is called inside the onCreate lifecycle method. Is it possible to directly launch the activity in landscape orientation. Since we need the activity to be in landscape mode only on phones we are not able to set the orientation in manifest.xml file. (In tablets the activity should support any orientation)

Upvotes: 1

Views: 224

Answers (1)

Charles Annic
Charles Annic

Reputation: 895

You can use the manifest to set orientation and get the value from ressources.

<activity
            android:name=".activities.MainActivity"
            android:label="@string/app_name"
            android:screenOrientation="@integer/orientation" />

In your integers.xml files set the value as follow :

<integer name="orientation">0</integer> <!-- Force landscape mode -->

<integer name="orientation">1</integer> <!-- Force portrait mode -->

<integer name="orientation">2</integer> <!-- Use phone's orientation -->

Just create a integers.xml file for phones and another for tablets.

Upvotes: 0

Related Questions