問(wèn)題描述
我一直在尋找一種 Kivy 解決方案來(lái)捕獲 Android 設(shè)備從一個(gè)方向到另一個(gè)方向的旋轉(zhuǎn).我已經(jīng)嘗試了以下兩種窗口方法,但在旋轉(zhuǎn)設(shè)備時(shí)都沒(méi)有執(zhí)行 on_rotate
或 rotate_screen
例程.我看到 java 中有一個(gè) 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 中得到的是以下消息,表明設(shè)備已旋轉(zhuǎn),但我的應(yīng)用從未看到這些事件.
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}
推薦答案
我認(rèn)為 on_rotate 只跟蹤 Kivy 的內(nèi)部旋轉(zhuǎn)(這是在 OpenGL 中完成的,與 Android 級(jí)別旋轉(zhuǎn)無(wú)關(guān)).
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 來(lái)使用普通的 Java 方法,但我不知道細(xì)節(jié).一個(gè)可能同樣有效的簡(jiǎn)單解決方案是觀察 Window.size
(from kivy.core.window import Window
) - 這應(yīng)該會(huì)檢測(cè)到從縱向到橫向的變化.
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.
這篇關(guān)于如何在 Kivy 中檢測(cè) Android 上的屏幕旋轉(zhuǎn)?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!