Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android portrait or landscape [duplicate]

Tags:

android

Possible Duplicate:
Check orientation on Android phone

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

like image 716
pawan pathak Avatar asked Feb 21 '11 07:02

pawan pathak


People also ask

How do I force horizontal orientation on Android?

When on the main screen, under the orientation section, you will see a number of options like 'Auto-rotate OFF', 'Auto-rotate ON', 'Forced Portrait' and 'Forced Landscape'. As the names suggest, you can use these buttons as one-tap shortcuts to toggle the orientation of your device.

Are two types of screen orientation in Android?

As with almost all smartphones, Android supports two screen orientations: portrait and landscape. When the screen orientation of an Android device is changed, the current activity being displayed is destroyed and re-created automatically to redraw its content in the new orientation.

How do I manage portrait and landscape on Android?

Rotate your phone to change the screen orientation (if Auto Rotate is enabled). If Auto Rotate is enabled, your phone's screen will automatically flip to portrait mode when you are holding it upright. When you are holding it horizontally, it will automatically switch to Landscape mode.


2 Answers

if(context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) 
{
    // code to do for Portrait Mode
} else {
    // code to do for Landscape Mode         
}
like image 127
Rohit Sharma Avatar answered Oct 05 '22 05:10

Rohit Sharma


Use getResources().getConfiguration().orientation.

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

like image 36
hackbod Avatar answered Oct 05 '22 05:10

hackbod