Tuesday

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

How to know screen Orientation in android, and set screen orientation as your request.

Overall orientation of the screen. May be one of ORIENTATION_LANDSCAPEORIENTATION_PORTRAIT.

The current configuration, as used to determine which resources to retrieve etc, as available from the Resources' Configuration object as:
getResources().getConfiguration().orientation
and full code:

public int getScreenOrientation() {

	Display getOrient = getWindowManager().getDefaultDisplay();

int orientation = Configuration.ORIENTATION_UNDEFINED;

if (getOrient.getWidth() == getOrient.getHeight()) {

orientation = Configuration.ORIENTATION_SQUARE;

} else {

if (getOrient.getWidth() < getOrient.getHeight()) {

orientation = Configuration.ORIENTATION_PORTRAIT;

} else {

orientation = Configuration.ORIENTATION_LANDSCAPE;

}

}

return orientation;

}



all device configuration information that can impact the resources the application retrieves. This includes both user-specified configuration options (locale and scaling) as well as device configurations (such as input modes, screen size and screen orientation).

More Details: http://developer.android.com/reference/android/content/res/Configuration.html

1 comments

Posts a comment

Related Posts  www.prandroid.com...
 
© 2011 Android Programming Tutorails | 2012 Templates
Designed by Blog Thiết Kế
Back to top