Android的 - 反向检测横向 [英] Android - detect reverse landscape orientation

查看:146
本文介绍了Android的 - 反向检测横向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要以检测反向横向到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?

推荐答案

使用的 OrientationEventListener 得到取向度的手机。

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

一旦你创建了一个侦听器,并调用使能(),<一个href=\"http://developer.android.com/reference/android/view/OrientationEventListener.html#onOrientationChanged%28int%29\"相对=nofollow> 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.

不要忘了用<一个href=\"http://developer.android.com/reference/android/hardware/SensorManager.html#SENSOR_DELAY_NORMAL\"相对=nofollow> 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的 - 反向检测横向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆