Android - detect reverse landscape orientation

懵懂的女人 提交于 2019-12-23 12:50:16

问题


I need to detect reverse landscape orientation in order to prevent user to start capturing vertical videos.

I've implemented 2 layouts in layout-land and layout-port folders with different set of controls. The problem is that Android doesn't allow me to create a separate layout specifically for reverse landscape. I need this because video is recorded upside down in this case, albeit UI is displayed correctly.

If I rotate device from 0 to 180 orientation Android doesn't even call onCreate() of my activity, but video becomes flipped in this case.

Can somebody suggest a working example how to detect certain device orientation (reverse landscape in my case) to use another layout for this orientation?


回答1:


Use an OrientationEventListener to get the orientation in degrees of the phone.

Once you create a listener and call enable(), onOrientationChanged(int) will be called whenever the phone's orientation is changed.

You can then check if it is out of the ranges you want the phone to be in.

Don't forget to use SENSOR_DELAY_NORMAL as your rate. This way it will only be called when an orientation change happens that you actually care about, not the small changes that usually happen while a user is handling their phone.



来源:https://stackoverflow.com/questions/18052035/android-detect-reverse-landscape-orientation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!