如何在 Kivy 中检测 Android 上的屏幕旋转?

How to detect screen rotation on Android in Kivy?(如何在 Kivy 中检测 Android 上的屏幕旋转?)
本文介绍了如何在 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 上的屏幕旋转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)