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.
Window.on_rotate(self.on_rotate)
Window.bind(on_rotate=self.rotate_screen)
我在 logcat 中得到的是以下消息,表明设备已旋转,但我的应用从未看到这些事件.
What I do get in the logcat is the following messages indicating the device has rotated but my app never see these events.
I/InputReader(270): Reconfiguring input devices. changes=0x00000004
I/InputReader(270): Device reconfigured: id=3, name='ilitek_i2c', surface size is now 1280x800, mode is 1
I/ActivityManager(270): Config changed: {1.0 0mcc0mnc en_US sw800dp w1280dp h752dp xlrg land finger -keyb/v/h -nav/h s.8}
推荐答案
我认为 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 上的屏幕旋转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Kivy 中检测 Android 上的屏幕旋转?
基础教程推荐
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
