How to Check Android Device Screen Orientation
http://www.viralandroid.com/2016/01/how-to-check-android-device-screen-orientation.html
Android devices have both portrait and landscape mode. You can choose in which mode applications or activity to run. With the little bit code you can change screen orientation and display different layout in landscape and portrait mode. So, in this tutorial, you will learn to check android device (phone, tablet, tv) screen orientation programmatically and display different design in portrait and landscape mode.
There are many methods to check android device screen orientation. Here I will show some of the best ways to check android screen orientation. You can make different XML layout for different mode like below.
res/layout/main_xml_layout.xml
res/layout-large/main_xml _layout.xml
res/layout-xlarge/main_xml _layout.xml
res/layout-xlarge-land/main_xml _layout.xml
Related:
Check Internet Connection in Android
Load Image from URL (Internet) in Android
How to Capture Image from Android Camera and Display it Programmatically
Following are the different method to check android screen orientation.
This method shows you to check android device screen orientation using if else statement.
src/CheckAndroidDeviceScreenOrientation.java
This method shows how to check android device screen orientation using switch case.
src/CheckAndroidDeviceScreenOrientation.java
This method shows by using XML file to check screen orientation. First create a XML file something like android_layout.xml inside values-land and values-port folder and add following.
res/values-port/android_layout.xml
res/values-land/andrid_layout.xml
And add a line of following java code in your activity file.
context.getResources().getBoolean(R.bool.is_landscape)
These are the some methods to check android device screen orientation. Not only these you can also find others too.
There are many methods to check android device screen orientation. Here I will show some of the best ways to check android screen orientation. You can make different XML layout for different mode like below.
res/layout/main_xml_layout.xml
res/layout-large/main_xml _layout.xml
res/layout-xlarge/main_xml _layout.xml
res/layout-xlarge-land/main_xml _layout.xml
Related:
Check Internet Connection in Android
Load Image from URL (Internet) in Android
How to Capture Image from Android Camera and Display it Programmatically
Android Example: Check Android Screen Orientation Programmatically
Following are the different method to check android screen orientation.
Method 1:
This method shows you to check android device screen orientation using if else statement.
src/CheckAndroidDeviceScreenOrientation.java
Method 2:
This method shows how to check android device screen orientation using switch case.
src/CheckAndroidDeviceScreenOrientation.java
Method 3:
This method shows by using XML file to check screen orientation. First create a XML file something like android_layout.xml inside values-land and values-port folder and add following.
res/values-port/android_layout.xml
res/values-land/andrid_layout.xml
And add a line of following java code in your activity file.
context.getResources().getBoolean(R.bool.is_landscape)
These are the some methods to check android device screen orientation. Not only these you can also find others too.