【问题标题】:KivyMD why app on pc looks different on mobileKivyMD 为什么电脑上的应用在移动设备上看起来不一样
【发布时间】:2021-06-22 19:47:49
【问题描述】:

PC端和手机端的区别如下: 个人电脑 - https://imgur.com/GzGHEjR 手机 - https://imgur.com/GqudNbt 我需要做什么才能完成这项工作?我是否需要每次都运行移动应用来进行更改?

kv 文件在这里(我不知道如何缩进):

FloatLayout:
canvas:
    Color:
        rgba: 66/255, 66/255, 66/255, 1
    RoundedRectangle:
        pos: (5, 5)
        size: self.width -10, self.height -10
        radius: [50]


MDLabel:
    text: 'Amount'
    bold: True
    theme_text_color: 'Custom'
    text_color: 1, 1, 1, 1
    halign: 'center'
    pos_hint: {'center_x':0.15, 'center_y':0.6}

MDTextFieldRound:
    id: amount_text
    text: '0'
    size_hint: 0.15,0.05
    pos_hint: {'center_x':0.20, 'center_y':0.53}
    line_color: 76/255, 182/255, 172/255, 1
    foreground_color: 1, 1, 1, 1
    normal_color: 76/255, 182/255, 172/255, 1


MDLabel:
    text: 'From'
    bold: True
    theme_text_color: 'Custom'
    text_color: 1, 1, 1, 1
    halign: 'center'
    pos_hint: {'center_x': 0.38, 'center_y':0.6}

MDFillRoundFlatButton:
    id: menu_button1
    text: 'USD'
    font_size: 20
    pos_hint: {'center_x': 0.45, 'center_y': 0.53}
    size_hint: 0.23, 0.05
    md_bg_color: 76/255, 182/255, 172/255, 1
    on_press: app.menu1.open()


MDLabel:
    text: 'To'
    bold: True
    theme_text_color: 'Custom'
    text_color: 1, 1, 1, 1
    halign: 'center'
    pos_hint: {'center_x': 0.72, 'center_y':0.6}

MDFillRoundFlatButton:
    id: menu_button2
    text: 'ILS'
    font_size: 20
    pos_hint: {'center_x': 0.8, 'center_y': 0.53}
    size_hint: 0.23, 0.05
    md_bg_color: 76/255, 182/255, 172/255, 1
    on_press: app.menu2.open()


MDRaisedButton:
    pos_hint: {'center_x': 0.62, 'center_y': 0.53}
    size_hint: (None, None)
    width: dp(2100)
    md_bg_color: 66/255, 66/255, 66/255, 1
    on_press: app.change()

    Image:
        source: 'convert.png'


MDFillRoundFlatButton:
    text: 'Convert'
    pos_hint: {'x':0.8, 'center_y':0.4}
    md_bg_color: 100/255, 170/255, 210/255, 1
    on_press: app.convert()


MDTextField:
    text: '0'
    id: result
    pos_hint: {'center_x':0.5, 'center_y':0.3}
    size_hint: 0.3, 0.2
    font_size: 32
    halign: 'center'
    line_color_normal: 76/255, 182/255, 172/255, 1
    readonly: True

看起来您的帖子主要是代码;请添加更多详细信息。

【问题讨论】:

    标签: android kivy kivymd


    【解决方案1】:

    每当您进行像素测量时,请务必改用测量单位。例如,在您的 kv 文件中写入 font_size: dp(32)font_size: '32dp' 而不是 font_size: 32。这将确保尺寸在不同的屏幕密度下保持不变。请参阅Kivy Metrics 了解更多信息。

    如果您希望按钮和文本字段看起来完全相同,则需要手动创建自己的小部件子类并查看 KivyMD 源代码,因为没有简单的方法来配置这些小部件的半径。

    【讨论】:

    • 很好,我如何用按钮做到这一点?我尝试使用 pos/size 提示来做到这一点,但它在移动设备上效果不佳。我只能用正常的 pos/size 做到这一点?
    • 是的。大小提示和位置提示使用屏幕的尺寸,因此它们不是像素测量值。最初我认为有一种方法可以更改按钮半径以匹配文本字段,但事实并非如此。我已经更新了我的答案以反映这一点。
    【解决方案2】:

    在某些库(例如 kivymd)和一些固定的库(例如 kivy)中,设计因操作系统而异

    【讨论】:

    • 哦,所以kivy没有这样的问题?有没有比每次都进行更改并使用 buildozer 运行更好的方法?
    • 我不知道
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-20
    • 2012-11-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多