如何让 OrientationEventListener.onOrientationChanged() 仅在 UI 旋转时调用
可能的重复:
如何检测屏幕旋转
您好,
我想做的就是检测我的应用程序中的旋转变化。不过,我想我发现了Android系统的一个bug。如果您阅读以下内容:
http://developer.android.com /guide/practices/optimizing-for-3.0.html#Landscape
它说每次设备改变方向时,都会调用 Activity.onDestroy() ,并且 Activity.onCreate() 是叫。所以我想我可以使用 Display.getRotation() 方法来确定 Activity.onCreate() 方法中的新方向。然而,我发现由于某种原因,如果您将设备快速翻转 180 度,则永远不会调用 onCreate() (甚至 onResume())。我用 toast 消息证明了这一点。我的 Activity.onCreate() (或 Activity.onResume())中的 toast 消息会在设备旋转 90 度时出现,但不会在设备翻转 180 度时出现。所以重点是,上面文章中的说法并不总是正确的。
所以我决定使用 OrientationEventListener.onOrientationChanged()。这是可行的,但我不希望在我的应用程序中一遍又一遍地调用 onOrientationChanged() (设备的每次角度变化都会调用它)。这会减慢我正在做的其他事情。我只希望当我旋转屏幕足以使屏幕上的图像旋转时调用它,以便我可以确定我是否处于rotation_0、rotation_90、rotation_180或rotation_270。
当然这是用 xoom 的。
任何建议
Possible Duplicate:
How do I detect screen rotation
Hello,
All I want to do, is to detect a rotation change in my application. However, I think I found a bug in the Android system. If you read this:
http://developer.android.com/guide/practices/optimizing-for-3.0.html#Landscape
It say's that every time the device changes orientation, Activity.onDestroy() is called , and the Activity.onCreate() is called. So I figured I could just use the Display.getRotation() method to figure out my new orientation in the Activity.onCreate() method. However, I discovered that for some reason onCreate() (or even onResume()) is never called if you flip the device quickly by 180 degrees. I proved this using toast messages. My toast message in my Activity.onCreate() (or in Activity.onResume()) would appear with 90 degree turns, but not with 180 degree flips of the device. So the point is, the claim in the article above isn't always true.
So then I decided to use OrientationEventListener.onOrientationChanged(). This works, but I don't want onOrientationChanged() to be called over and over in my app (it gets called with every single change of degree of the device). This will slow down everything else I'm doing. I only want it to be called when I rotate the screen enough to get the image on the screen to rotate so that I can figure out if I'm at rotation_0,rotation_90,rotation_180, or rotation_270.
This is with a xoom of course.
Any suggestions
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此处详细回答。
Answered in detail here.