How do I make my Android app display in landscape mode only?

Android FAQ: How do I make my Android app display in landscape mode only?

To get an Android application to display in landscape mode only (to lock it in landscape mode), add this line to your Activity definition in the AndroidManifest.xml file:

android:screenOrientation="landscape"

For example, I’m writing an Android football game right now, and this is the definition for my main activity in the Android manifest file:

<activity
    android:name=".MainActivity"
    android:screenOrientation="landscape"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

Note that per the Android Activity documentation you can specify the mode as “landscape,” “sensorLandscape,” or “userLandscape”:

The documentation provides these definitions:

  • landscape - Landscape orientation (the display is wider than it is tall).
  • sensorLandscape - Landscape orientation, but can be either normal or reverse landscape based on the device sensor.
  • userLandscape - Landscape orientation, but can be either normal or reverse landscape based on the device sensor and the user’s sensor preference. If the user has locked sensor-based rotation, this behaves the same as landscape, otherwise it behaves the same as sensorLandscape.

In summary, if you wanted to see how to lock an Android application so that it’s always in landscape mode, I hope this is helpful.