Iam尝试将floatlayout对准中心,帮帮我吗? 上传图片以便了解...... 我的想法是在Kivy中重新创建Windows 8复古版,在按钮中添加图标windows 8 retro。
我的kv档案:
<SMAgro>:
AnchorLayout:
anchor_x: 'center'
anchor_y: 'center'
FloatLayout:
canvas:
Color:
rgb: [1,1,1,1]
Rectangle:
pos: self.pos
size: self.size
Button:
background_color: [.4,1,.1,1]
pos_hint: {'x': 0.26, 'y': 0.328571}
size_hint: 0.45, 0.3
text: "Equipamentos"
# StackLayout:
# pos: self.parent.pos
# size: self.parent.size
# orientation: 'lr-tb'
# Image:
# source: 'kivy.png'
# size_hint_x: None
# width: 74
# Label:
# size_hint_x: None
# width: 100
# text: "Equipamentos"
Button:
background_color: [.4,1,.1,1]
pos_hint: {'x': 0.26, 'y': 0.15}
size_hint: 0.225, 0.18
text: 'Configuracoes'
Button:
background_color: [.4,1,.1,1]
pos_hint: {'x': 0.486, 'y': 0.15}
size_hint: 0.225, 0.18
text: 'Sobre'
答案 0 :(得分:0)
您可以设置FloatLayout大小并添加pos_hint: {'center_y': 0.5, 'center_x': 0.5}
,例如:您最宽的按钮的size_hint_x = 0.45,按钮的size_hint_y = 0.18 + 0.3。
容器大小:size_hint: 0.45, 0.48
现在,如果按钮有size_hint: 1, 1
,它是父容器(FloatLayout)的100%宽度和高度,它等于45%宽度和48%窗口高度。
此代码显示居中的FloatLayout
FloatLayout:
pos_hint: {'center_y': 0.5, 'center_x': 0.5}
size_hint: 0.45, 0.48
canvas:
Color:
rgb: [1,1,1,1]
Rectangle:
pos: self.pos
size: self.size
Button:
background_color: [.4,1,.1,1]
pos_hint: {'x': 0, 'y': 0.375}
size_hint: 1, 0.625
text: "Equipamentos"
Button:
background_color: [.4,1,.1,1]
pos_hint: {'x': 0, 'y': 0}
size_hint: .5, 0.375
text: 'Configuracoes'
Button:
background_color: [.4,1,.1,1]
pos_hint: {'x': .5, 'y': 0}
size_hint: .5, 0.375
text: 'Sobre'