Android中的传感器坐标系不会改变,是吗?

我在许多地方读过:
One Screen Deserves Another:“API用于设备自然方向的传感器坐标系统不随设备移动而改变,与OpenGL坐标系相同.”

现在,我得到与此图像相同的读数:

我不明白的是:如果我旋转手机时坐标系没有改变(总是面向用户的屏幕),应始终在Y轴上施加重力.如果我将手机放在屏幕不再面向用户的位置,例如放在桌子上,重力应该应用在Z轴上,它应该只改变轴.

我的理解有什么问题?

谢谢!吉列尔莫.

最佳答案 当设备的屏幕方向改变时,交换轴.根据你引用的文章:

However, the Android sensor APIs define the sensor coordinate space to be relative to the top and side of the device — not the short and long sides. When the system reorients the screen in response to holding the phone sideways, the sensor coordinate system no longer lines up with the screen’s coordinate system, and you get unexpected rotations in the display of your app.

要根据需要访问未交换的值,请在值[]中使用索引3,4和5,否则同一篇文章中提到的一些建议可以很好地工作!

点赞