问题描述
我需要以检测反向横向到prevent用户开始捕捉垂直视频。
I need to detect reverse landscape orientation in order to prevent user to start capturing vertical videos.
我实现2的布局在<$ C $ C>布局土地和布局端口
不同的控件集文件夹。问题是,Android不容许我专门创建一个单独的布局反向的风景线。我需要这个,因为视频是在这种情况下录制的倒挂,虽然UI正确显示。
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.
如果我旋转设备从0到180的取向Android不甚至称之为的onCreate()
我的活动,但视频变得在这种情况下翻转。
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?
推荐答案
使用的得到取向度的手机。
Use an OrientationEventListener
to get the orientation in degrees of the phone.
一旦你创建了一个侦听器,并调用使能()
, onOrientationChanged(INT)
每当手机的方向改变将被调用。
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.
不要忘了用 SENSOR_DELAY_NORMAL
为您的费率。这样,它才会被调用时改变方向时发生您真正关心,而不是小的变化,当一个用户正在处理他们的电话通常发生。
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.
这篇关于Android的 - 反向检测横向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!