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.
精彩评论