How to detect screen rotation on Android in Kivy?(如何在 Kivy 中检测 Android 上的屏幕旋转?)
问题描述
我一直在寻找一种 Kivy 解决方案来捕获 Android 设备从一个方向到另一个方向的旋转.我已经尝试了以下两种窗口方法,但在旋转设备时都没有执行 on_rotate
或 rotate_screen
例程.我看到 java 中有一个 onConfigurationChanged
事件,但我找不到 Kivy 的相同事件处理.
I have been searching for a Kivy solution to capture the Android device rotation from one orientation to another. I have tried both of the window methods below but neither executes the on_rotate
or rotate_screen
routines when I rotate the device. I see there is an onConfigurationChanged
event in java but I can't find the same event handling for Kivy.
我在 logcat 中得到的是以下消息,表明设备已旋转,但我的应用从未看到这些事件.
What I do get in the logcat is the following messages indicating the device has rotated but my app never see these events.
推荐答案
我认为 on_rotate 只跟踪 Kivy 的内部旋转(这是在 OpenGL 中完成的,与 Android 级别旋转无关).
I think on_rotate only tracks Kivy's internal rotation (this is done in OpenGL and doesn't relate to the Android level rotation).
您可能可以使用 pyjnius 来使用普通的 Java 方法,但我不知道细节.一个可能同样有效的简单解决方案是观察 Window.size
(from kivy.core.window import Window
) - 这应该会检测到从纵向到横向的变化.
You can probably use pyjnius to work with the normal Java methods for this, but I don't know the details. A simple solution that may work just as well is to watch Window.size
(from kivy.core.window import Window
) - this should detect the change from portrait to landscape.
这篇关于如何在 Kivy 中检测 Android 上的屏幕旋转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!