开发者

how do I know what the orientation is in android? [duplicate]

开发者 https://www.devze.com 2023-02-22 03: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

I am writing an app that requires my program to know the difference be开发者_高级运维tween whether it is in landscape mode, or in portrait. how would I go about finding this out. currently I am using the getRequestedOrientation(), but that is always returning the number 2, which basically just means that it will change depending on which way the phone is turned (as apposed to being 0 which is landscape, or 1 which is portrait.) is there a better way of doing this?


You can check this in methods other than onConfigurationChanged by using the method from this answer:

getResources().getConfiguration().orientation

which will be equal to one of the following:

  • Configuration.ORIENTATION_PORTRAIT
  • Configuration.ORIENTATION_LANDSCAPE
  • Configuration.ORIENTATION_SQUARE


in onConfigurationChanged(Configurtion), the configuration object holds the information about the orientation. According to the reference, it can either be PORTRAIT, SQUARE or LANDSCAPE only.

0

精彩评论

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