Android:屏幕方向报告太慢?
我正在使用 Display.getRotation()
方法来确定我的应用程序中屏幕的当前方向,根据 Google 的这篇有用的博客文章:
http://android-developers.blogspot.com/2010/09/one-screen-turn-deserves- another.html
简而言之,我有一个绘图应用程序,允许用户在屏幕上绘制形状等,并且绘图画布需要保持相同的方向,但我仍然想要选项菜单,当用户开始使用不同方向的设备进行绘图时,等等,以翻转到正确的位置。
在画布的 onDraw()
中,我从 getRotation()
请求方向,然后将画布旋转回“0”位置,以便从最终用户的角度来看,画布永远不会移动。工作起来就像一个魅力除了,如果用户非常快速翻转设备......那么getRotation()
报告旋转为0,因此画布不会向后旋转,使绘图看起来翻转或旋转。
有趣的是,标题栏和选项菜单确实会翻转……所以不确定他们从哪里获得方向。如果用户随后开始绘图,则对 onDraw()
的后续调用将获取正确的旋转值,并且绘图将返回到正确的位置,但正如您可以想象的那样,这有点令人不安/烦人。有什么策略来处理这个问题吗?
谢谢。
I am using the Display.getRotation()
method to determine the current orientation of the screen in my App, per this helpful blog entry from Google:
http://android-developers.blogspot.com/2010/09/one-screen-turn-deserves-another.html
In a nutshell, I have a drawing app that allows the user to draw shapes, etc to the screen, and the drawing canvas needs to stay in the same orientation, but I still wanted to the Options menu, etc to flip to the correct location if and when the user starts drawing with the device in a different orientation.
In onDraw()
for the canvas, I request the orientation from getRotation()
and then rotate the canvas back to the '0' location so that from the end-user's perspective, the canvas never moves. Works like a charm EXCEPT if the user flips the device VERY quickly... then getRotation()
reports a rotation of 0, and thus the canvas doesn't rotate back, making the drawing appear flipped or turned.
Interestingly, the title bar and options menus do flip... so not sure where they are getting the orientation from. If the user then starts to draw, the subsequent call to onDraw()
gets the correct rotation vale and the drawing goes back to the correct location, but it is a bit unnerving/annoying as you can imagine. Any strategies on dealing with this?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试使用 getOrientation() 代替...我不确定您的问题源于何处,但谁知道,它可能会给您带来不同的结果。
You could try using getOrientation() instead... I'm not sure where your issue stems from but who knows, it could give you a different result.
使用 onOrientationChanged()。它返回当前角度(以度为单位)。它似乎可以可靠地适应显示方向的变化。我将角度转换为 4 个标准方向,如下所示:
Use onOrientationChanged(). It returns the current angle in degrees. It seems to work reliably for display orientation changes. I convert the angle into the 4 standard orientations like this: