6

Possible Duplicate:
Check orientation on Android phone

how to know programatically whether screen is in portrait or landscape mode.please help me

Community
  • 1
  • 1
pawan pathak
  • 89
  • 1
  • 1
  • 7

4 Answers4

22
if(context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) 
{
    // code to do for Portrait Mode
} else {
    // code to do for Landscape Mode         
}
Rohit Sharma
  • 13,787
  • 8
  • 57
  • 72
3

getResources().getConfiguration().orientation

or for listening to orientation events : http://android-developers.blogspot.in/2010/09/one-screen-turn-deserves-another.html

or use OrientationEventListener

Reno
  • 33,594
  • 11
  • 89
  • 102
3

Use getResources().getConfiguration().orientation.

http://developer.android.com/reference/android/content/res/Configuration.html#orientation

hackbod
  • 90,665
  • 16
  • 140
  • 154
1

You can detect the current width and height. If the height is longer than the width the screen is in portrait mode, otherwise it is landscape.

kgiannakakis
  • 103,016
  • 27
  • 158
  • 194