Home >Java >javaTutorial >How Can I Determine if My Android Device is in Landscape or Portrait Mode?

How Can I Determine if My Android Device is in Landscape or Portrait Mode?

DDD
DDDOriginal
2024-12-07 15:14:16407browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn