如何在 Kivy 中检测 Android 上的屏幕旋转? [英] How to detect screen rotation on Android in Kivy?

查看:30
本文介绍了如何在 Kivy 中检测 Android 上的屏幕旋转?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一种 Kivy 解决方案来捕获 Android 设备从一个方向到另一个方向的旋转.我已经尝试了以下两种窗口方法,但在旋转设备时都没有执行 on_rotaterotate_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 上的屏幕旋转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆