How to know the orientation of the screen?

Asked

Viewed 1,306 times

2

Which code perceives and returns the orientation of the screen?

If the cell phone is standing or lying down ?

2 answers

5

Configuration configuration = getResources().getConfiguration();

    if (configuration.orientation == Configuration.ORIENTATION_LANDSCAPE){
        //...
    }else{ 
        //...
    }

In this example, it checks whether the screen position is Landscape (lying) if not, it can only be in Portrait (standing)!

Very simple.

2

To check orientation just use this code:

getResources().getConfiguration().orientation

There is a feedback for each type of guidance, which you can check below:

  • ORIENTATION_UNDEFINED = 0
  • ORIENTATION_PORTRAIT = 1
  • ORIENTATION_LANDSCAPE = 2
  • ORIENTATION_SQUARE = 3

Details

Browser other questions tagged

You are not signed in. Login or sign up in order to post.