kivy 宽度和高度在适用于 android 的 kivy 应用程序中不起作用

问题描述 投票:0回答:0

当我运行我的代码时,它会根据窗口在 pc 中正确排列,但是我会调整大小,但是当我使用 buildozer 将其制作为应用程序时,它不会被排列,因为它无法访问 root.height 和 root.width。

帮我找到如何在移动或安卓设备上获取屏幕的宽度和高度。

import kivy
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.button import Button
from kivy.uix.label import Label

Builder.load_string("""
<LoginScreen>:
    FloatLayout:
        name: 'login_p'
        cols:1
        FloatLayout:
            size: root.width, root.height/2
            Label:
                text: "Login to your Account"
                size_hint: 0.8, 0.25
                pos_hint: {"x":0.1, "top":1}
                font_size: (root.width**2 + root.height**2) / 14**4

            Label:
                size_hint: 0.5,0.12
                pos_hint: {"x":0, "top":0.8}
                text: "Username : "
                font_size: (root.width**2 + root.height**2) / 14**4

            TextInput:
                pos_hint: {"x":0.4, "top":0.8}
                size_hint: 0.5, 0.12
                id: namee
                multiline: False
                font_size: (root.width**2 + root.height**2) / 14**4

            Label:
                size_hint: 0.5,0.12
                pos_hint: {"x":0, "top":0.8-0.13}
                text: "Password : "
                font_size: (root.width**2 + root.height**2) / 14**4

            TextInput:
                pos_hint: {"x":0.4, "top":0.8-0.13}
                size_hint: 0.5, 0.12
                id: password
                multiline: False
                font_size: (root.width**2 + root.height**2) / 14**4

        Button:
            pos_hint:{"x":0.2,"y":0.35}
            size_hint: 0.6, 0.1
            font_size: (root.width**2 + root.height**2) / 17**4
            text: "Already have an Account? Log In"
""")

class LoginScreen(Screen):
    pass    

class mainApp(App):
    def build(self):
        sm = ScreenManager()
        sm.add_widget(LoginScreen(name='login'))
        return sm

if __name__ == '__main__':
    mainApp().run()
python kivy apk kivymd buildozer
© www.soinside.com 2019 - 2024. All rights reserved.