开发者

android portrait or landscape [duplicate]

开发者 https://www.devze.com 2023-02-12 21:15 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Check orientation on Android phone
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Check orientation on Android phone

how to know programatically whether screen is in portrait开发者_运维知识库 or landscape mode.please help me


if(context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) 
{
    // code to do for Portrait Mode
} else {
    // code to do for Landscape Mode         
}


Use getResources().getConfiguration().orientation.

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


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号