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

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

问题描述

我一直在寻找一种Kivy解决方案,以捕获Android设备从一个方向到另一个方向的旋转.我已经尝试了下面的两个window方法,但是在旋转设备时都没有执行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天全站免登陆