Android Screen Orientation ExampleThe 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:
Android Portrait and Landscape mode screen orientation exampleIn 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.xmlFile: activity_main.xml
Activity classFile: MainActivity.java
activity_second.xmlFile: activity_second.xml
SecondActivity classFile: SecondActivity.java
AndroidManifest.xmlFile: 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:![]() ![]()
Next TopicAndroid UI Widgets Tutorial
|
JavaTpoint offers too many high quality services. Mail us on h[email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected].
Duration: 1 week to 2 week