按钮宽度在PC上是对称的,但在Android Python/Kivy上不是对称的
我创建了一个自定义切换按钮,设置size_hint_x
to none
放置width
。该按钮在PC上是完美的,但是在Android上,按钮的宽度似乎已经重置。
myWidget.kv:
#:import Window kivy.core.window.Window
<MyButton>:
size_hint_x: None
width: Window.width/3
font_name: "path/to/font.ttf"
md_bg_color: app.theme_cls.bg_dark
background_down: get_color_from_hex("#2e5871")
font_color_normal: app.theme_cls.primary_color
font_color_down: app.theme_cls.primary_light
allow_no_selection: False
mywidget.py.py
from kivymd.uix.behaviors.toggle_behavior import MDToggleButton
from kivymd.uix.button import MDRectangleFlatButton
class MyButton(MDRectangleFlatButton, MDToggleButton):
def __init__(self, **kwargs):
self.background_normal = 1, 1, 1, 1
super().__init__(**kwargs)
位置我正在使用按钮:
MDRelativeLayout:
size_hint: 1, None
height: dp(45)
MyButton:
text: "List 1"
group: "list"
pos_hint: {"top":1, "left":1}
MyButton:
text: "List 2"
group: "list"
pos_hint: {"top":1, "center_x":.5}
MyButton:
text: "List 3"
group: "list"
pos_hint: {"top":1, "right":1}
这是应用程序images
I created a custom Toggle Button, setting size_hint_x
to None
to put width
. The button is perfect on pc but on android it is as if the width of the button had been reset.
MyWidget.kv:
#:import Window kivy.core.window.Window
<MyButton>:
size_hint_x: None
width: Window.width/3
font_name: "path/to/font.ttf"
md_bg_color: app.theme_cls.bg_dark
background_down: get_color_from_hex("#2e5871")
font_color_normal: app.theme_cls.primary_color
font_color_down: app.theme_cls.primary_light
allow_no_selection: False
MyWidget.py
from kivymd.uix.behaviors.toggle_behavior import MDToggleButton
from kivymd.uix.button import MDRectangleFlatButton
class MyButton(MDRectangleFlatButton, MDToggleButton):
def __init__(self, **kwargs):
self.background_normal = 1, 1, 1, 1
super().__init__(**kwargs)
Location I'm using the button:
MDRelativeLayout:
size_hint: 1, None
height: dp(45)
MyButton:
text: "List 1"
group: "list"
pos_hint: {"top":1, "left":1}
MyButton:
text: "List 2"
group: "list"
pos_hint: {"top":1, "center_x":.5}
MyButton:
text: "List 3"
group: "list"
pos_hint: {"top":1, "right":1}
Here is the app images
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过更改
size_hint_x
而不是width
。
The issue was resolved by changing the
size_hint_x
instead of thewidth
.Obrigado @ApuCoder