Screen Orientation
Screen Orientation
UNIT II
Screen Orientations
Screen Orientation, also known as screen rotation, is
the attribute of activity element in android.
When screen orientation change from one state to other,
it is also known as configuration change.
States of Screen orientation
<activity
android:name="package_name.Your_ActivityName"
android:screenOrientation="orientation_type">
</activity>
Example:
android:screenOrientation="orientation_type">
two activities of different screen orientation.
o The first activity will be as “portrait” orientation and
o Second activity as “landscape” orientation state.
Step-by-Step demonstration:
Creating the activities: There will be two activities and
hence two XML files, one for each activity.
1. activity_main.xml: XML file for first activity consist of
constraint layout with Button and Text View in it. This
activity is in Landscape state.
2. activity_next.xml: XML file for second activity consist
of constraint layout with Text View in it. This activity is
in Landscape state.
Creating the Java file: There will be two activities and
hence two Java files, one for each activity.
1. MainActivity.java: Java file for Main Activity, in
which setOnClick() listener is attached to the button to
launch next activity with different orientation.
2. NextActivity.java: Java file for Next Activity which is in
Landscape mode.
Updating the AndroidManifest file:
In AndroidManifest.xml file, add the screenOrientation
state in activity along with its orientation.
Here, provide “portrait” orientation for MainActivity and
“landscape” for NextActivity.