Android screenOrientation vs Rotation

时间:2012-11-14 19:55:59

标签: android

我正在使用OrientationEventListener在用户旋转设备时正确定位我的活动。我通过调用Activity.setRequestedOrientation(int)来定位活动。

我的问题是OrientationEventListener从“自然设备位置”返回角度。 setRequestedOrientation接受诸如SCREEN_ORIENTATION_PORTRAIT等参数。要从角度转换到方向,我需要知道“自然设备位置”是什么,即它是横向左侧,横向右侧,纵向还是纵向反转。不幸的是,API似乎没有办法找到答案。

怎么办?

2 个答案:

答案 0 :(得分:0)

点击此链接:Check orientation on Android phone

我认为你可以使用onConfigurationChanged在Orientation改变时调用。

答案 1 :(得分:0)

您可以使用以下内容:

int orientation = getResources().getConfiguration().orientation;

来自文档:

Overall orientation of the screen. May be one of ORIENTATION_LANDSCAPE, ORIENTATION_PORTRAIT.

问候。