Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

java
communitycreator

How to set the screen orientation for an Android application

Arooj Fatima

Android Screen Orientation is the direction of how an activity or a screen view appears in an application. It can be of four types:

How to set android screen orientation

To be added in AndroidManifest.xml: android:screenOrientation="orientationType"

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapplication">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.MyApplication"> 
        
        <activity android:name=".MainActivity"
            android:screenOrientation="landscape">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Explanation

  • The desired screen orientation is to be added into the AndroidManifest.xml file
    • i.e., android:screenOrientation="landscape"
  • The rest of the code remains the same

However, it is simpler to change the orientation in Android studio.

To do so, execute the following in activity_main.xml:

RELATED TAGS

java
communitycreator
RELATED COURSES

View all Courses

Keep Exploring