Javatpoint Logo
Javatpoint Logo

Android Screen Orientation Example

The screenOrientation is the attribute of activity element. The orientation of android activity can be portrait, landscape, sensor, unspecified etc. You need to define it in the AndroidManifest.xml file.

Syntax:

Example:

The common values for screenOrientation attribute are as follows:

ValueDescription
unspecifiedIt is the default value. In such case, system chooses the orientation.
portraittaller not wider
landscapewider not taller
sensororientation is determined by the device orientation sensor.

Android Portrait and Landscape mode screen orientation example

In this example, we will create two activities of different screen orientation. The first activity (MainActivity) will be as "portrait" orientation and second activity (SecondActivity) as "landscape" orientation type.

activity_main.xml

File: activity_main.xml

Activity class

File: MainActivity.java

activity_second.xml

File: activity_second.xml

SecondActivity class

File: SecondActivity.java

AndroidManifest.xml

File: AndroidManifest.xml

In AndroidManifest.xml file add the screenOrientation attribute in activity and provides its orientation. In this example, we provide "portrait" orientation for MainActivity and "landscape" for SecondActivity.


Output:

android screen orientation example output 1 android screen orientation example output 2






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA