当screenOrientation =“sensorLandscape”时,听取方向改变

时间:2013-05-16 13:01:27

标签: android android-orientation

我想听一个活动的方向改变。我尝试了一些常见的事情,

  • onConfigurationChange,其中包含android:configChanges元素的方向 在清单中,
  • 没有重新启动活动,(用断点证明),所以我不能在轮换后检查getWindowManager().getDefaultDisplay().getRotation(),除非我在绘制线程中不断检查,这是浪费。
  • 我可以使用OrientationEventListener,但是每次更换手机都会调用它,这样做(imo)也很浪费。

我正在尝试检测与LandscapeLeft和LandscapeRight的区别。我不确定此时如何处理它。

1 个答案:

答案 0 :(得分:2)

我不相信OrientationEventListener一定会告诉你屏幕的方向是否已经改变,因为它只返回度数。

使用getWindowManager().getDefaultDisplay().getRotation()可能是要走的路,但你必须知道设备的默认方向,因为这只会告诉你基于默认值的轮换。

有一个不错的博客,关于使用各种传感器进行方向更改和坐标系here.