How can I check if the Android phone is in Landscape or Portrait?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How can I create this custom Bottom Navigation on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
Old post I know. Whatever the orientation may be or is swapped etc. I designed this function that is used to set the device in the right orientation without the need to know how the portrait and landscape features are organised on the device.
Works like a charm!
Here is code snippet demo how to get screen orientation was recommend by hackbod and Martijn:
❶ Trigger when change Orientation:
❷ Get current orientation as hackbod recommend:
❸There are alternative solution for get current screen orientation ❷ follow Martijn solution:
★Note: I was try both implement ❷ & ❸, but on RealDevice (NexusOne SDK 2.3) Orientation it returns the wrong orientation.
★So i recommend to used solution ❷ to get Screen orientation which have more advantage: clearly, simple and work like a charm.
★Check carefully return of orientation to ensure correct as our expected (May be have limited depend on physical devices specification)
Hope it help,
Some time has passed since most of these answers have been posted and some use now deprecated methods and constants.
I've updated Jarek's code to not use these methods and constants anymore:
Note that the mode
Configuration.ORIENTATION_SQUARE
isn't supported anymore.I found this to be reliable on all devices I've tested it on in contrast to the method suggesting the usage of
getResources().getConfiguration().orientation
The Android SDK can tell you this just fine:
There is one more way of doing it:
Use
getResources().getConfiguration().orientation
it's the right way.You just have to watch out for different types of landscapes, the landscape that the device normally uses and the other.
Still don't understand how to manage that.