Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (3.5k points)

How can I check if the Android phone is in Landscape or Portrait?

1 Answer

0 votes
by (46k points)

The present configuration, as used to know which resources to retrieve, is present in the Resources' Configuration object:

getResources().getConfiguration().orientation;

You can view for orientation by searching at its value:

int orientation = getResources().getConfiguration().orientation;

if (orientation == Configuration.ORIENTATION_LANDSCAPE) {

    // In landscape

} else {

    // In portrait

}

More data can be observed in the Android Developer.

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...