0% found this document useful (0 votes)
15 views3 pages

Screen Orientation

The document discusses screen orientations in Android application development. It defines various screen orientation states and describes how to set the orientation of activities in the AndroidManifest.xml file. It also provides an example of creating two activities with different orientations.

Uploaded by

dharshujaym
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

Screen Orientation

The document discusses screen orientations in Android application development. It defines various screen orientation states and describes how to set the orientation of activities in the AndroidManifest.xml file. It also provides an example of creating two activities with different orientations.

Uploaded by

dharshujaym
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Mobile Application Development

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

 There are various possible screen orientation states for


any android application
 ActivityInfo.SCREEN_ORIENTATION_LANDSCAP
E
 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFI
ED
 ActivityInfo.SCREEN_ORIENTATION_USER
 ActivityInfo.SCREEN_ORIENTATION_SENSOR
 ActivityInfo.SCREEN_ORIENTATION_BEHIND
 ActivityInfo.SCREEN_ORIENTATION_NOSENSOR
 ActivityInfo.SCREEN_ORIENTATION_SENSOR_L
ANDSCAPE
 ActivityInfo.SCREEN_ORIENTATION_SENSOR_P
ORTRAIT
 ActivityInfo.SCREEN_ORIENTATION_REVERSE_
PORTRAIT
The initial orientation of the Screen has to be defined in
the AndroidManifest.xml file.
Syntax:

<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.

You might also like