Home >Java >javaTutorial >How Can I Determine if My Android Device is in Landscape or Portrait Mode?
Determining Device Orientation on Android
To ascertain the orientation of an Android device (either Landscape or Portrait), utilize the following approach:
Solution:
The device's current orientation, which influences the retrieval of resources, is accessible through the Resources' Configuration object:
getResources().getConfiguration().orientation;
Evaluate the orientation by examining its value:
int orientation = getResources().getConfiguration().orientation; if (orientation == Configuration.ORIENTATION_LANDSCAPE) { // In landscape } else { // In portrait }
For further information, refer to the Android Developer documentation.
The above is the detailed content of How Can I Determine if My Android Device is in Landscape or Portrait Mode?. For more information, please follow other related articles on the PHP Chinese website!