我正在尝试使用Kivy和Python创建一个包含许多屏幕的简单应用程序,其中包含文本信息。我真的是编码方面的新手。问题是,当我用Buildozer做apk时,大约需要10秒钟才能在手机上启动(5秒钟-启动屏幕,然后5秒钟是黑屏)。
我认为问题在于App正在尝试在启动过程中加载每个屏幕。有什么方法可以使应用程序加载更快?
main.py
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.scrollview import ScrollView
from kivy.properties import StringProperty
from kivy.uix.label import Label
class HomeScreen(Screen):
pass
class ScrollableLabel(ScrollView):
pass
class FirstScreen(Screen):
pass
class SecondScreen(Screen):
pass
...
class FortyScreen(Screen):
pass
GUI = Builder.load_file("main.kv")
class MainApp(App):
def build(self):
return GUI
def change_screen(self, screen_name):
screen_manager = self.root.ids['screen_manager']
screen_manager.current = screen_name
MainApp().run()
main.kv
#:include firstscreen.kv
#:include secondscreen.kv
...
#:include fortyscreen.kv
GridLayout:
cols: 1
ScreenManager:
id: screen_manager
HomeScreen:
name: "home_screen"
id: home_screen
FirstScreen:
name: "first_screen"
id: first_screen
SecondScreen:
name: "second_screen"
id: second_screen
...
FortyScreen:
name: "normal"
id: normal
firstscreen.kv
<FirstScreen>:
GridLayout:
padding: [15,0,15,15]
canvas:
Color:
rgb: utils.get_color_from_hex("#ffffff")
Rectangle:
size: self.size
pos: self.pos
cols:1
ScrollView:
Label:
color: 0, 0, 0, 1
background_color: 255, 255, 255, 1
size_hint_y: None
height: self.texture_size[1]
text_size: self.width, None
text:"""Really long long string""" * 40
BoxLayout:
cols:2
size_hint_y: None
Button:
color: 0, 0, 0, 1
size_hint_y: None
background_color: 255, 255, 255, 1
text:
"Menu"
on_release:
app.change_screen("home_screen")