How to detect screen rotation on Android in Kivy?

♀尐吖头ヾ 提交于 2021-02-20 17:54:26

问题


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)        

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}

回答1:


I think on_rotate only tracks Kivy's internal rotation (this is done in OpenGL and doesn't relate to the Android level rotation).

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.



来源:https://stackoverflow.com/questions/39430824/how-to-detect-screen-rotation-on-android-in-kivy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!