KivyMD 为什么 PC 上的应用程序在移动设备上看起来不一样
KivyMD why app on pc looks different on mobile
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
看起来你的 post 主要是代码;请添加更多详细信息。
某些库(例如 kivymd)的设计因操作系统而异,而某些库(例如 kivy)是固定的
无论何时进行像素测量,请务必使用测量单位。例如,在您的 kv 文件中写 font_size: dp(32)
或 font_size: '32dp'
而不是 font_size: 32
。这将确保尺寸在不同的屏幕密度下保持不变。有关更多信息,请参阅 Kivy Metrics。
如果您希望按钮和文本字段看起来完全一样,您需要手动创建自己的小部件子类并查看 KivyMD 源代码,因为没有简单的方法来配置这些小部件的半径。
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
看起来你的 post 主要是代码;请添加更多详细信息。
某些库(例如 kivymd)的设计因操作系统而异,而某些库(例如 kivy)是固定的
无论何时进行像素测量,请务必使用测量单位。例如,在您的 kv 文件中写 font_size: dp(32)
或 font_size: '32dp'
而不是 font_size: 32
。这将确保尺寸在不同的屏幕密度下保持不变。有关更多信息,请参阅 Kivy Metrics。
如果您希望按钮和文本字段看起来完全一样,您需要手动创建自己的小部件子类并查看 KivyMD 源代码,因为没有简单的方法来配置这些小部件的半径。