問題描述
我一直在尋找一種 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 上的屏幕旋轉?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!