如何删除 kivy BoxLayout 中多余的 space?
How do I remove extra unwanted space in kivy BoxLayout?
<BoxExample@BoxLayout>:
orientation: "vertical"
BoxLayout:
orientation: "horizontal"
size_hint_y: None
Button:
text: "Logo"
size_hint: None, None
width: "80dp"
height: "40dp"
pos_hint: {'top': 1}
Button:
text: "Menu"
size_hint: 1, None
height: "40dp"
pos_hint: {'top': 1}
Button:
text: "Body"
Button:
text: "Footer"
size_hint: 1, None
height: "40dp"
上图那个黑色space,我要去掉
但是添加 size_hint_y 后: None 差距已经缩小,如图所示。
只需添加:
height: self.minimum_height
到BoxLayout
:
<BoxExample@BoxLayout>:
orientation: "vertical"
BoxLayout:
orientation: "horizontal"
size_hint_y: None
height: self.minimum_height
Button:
text: "Logo"
size_hint: None, None
width: "80dp"
height: "40dp"
pos_hint: {'top': 1}
Button:
text: "Menu"
size_hint: 1, None
height: "40dp"
pos_hint: {'top': 1}
Button:
text: "Body"
Button:
text: "Footer"
size_hint: 1, None
height: "40dp"
这是由于 BoxLayout 提供的每个子部件都相等 space 但这里您更改了按钮的大小 BoxLayout.You 还需要更改 BoxLayout 的大小否则它会显示黑色。
<BoxExample@BoxLayout>:
orientation: "vertical"
BoxLayout:
orientation: "horizontal"
size_hint: None,None
size:root.size[0],"40dp"
Button:
text: "Logo"
size_hint: None, None
width: "80dp"
height: "40dp"
pos_hint: {'top': 1}
Button:
text: "Menu"
size_hint: 1, None
height: "40dp"
pos_hint: {'top': 1}
Button:
text: "Body"
Button:
text: "Footer"
size_hint: 1, None
height: "40dp"
<BoxExample@BoxLayout>:
orientation: "vertical"
BoxLayout:
orientation: "horizontal"
size_hint_y: None
Button:
text: "Logo"
size_hint: None, None
width: "80dp"
height: "40dp"
pos_hint: {'top': 1}
Button:
text: "Menu"
size_hint: 1, None
height: "40dp"
pos_hint: {'top': 1}
Button:
text: "Body"
Button:
text: "Footer"
size_hint: 1, None
height: "40dp"
上图那个黑色space,我要去掉 但是添加 size_hint_y 后: None 差距已经缩小,如图所示。
只需添加:
height: self.minimum_height
到BoxLayout
:
<BoxExample@BoxLayout>:
orientation: "vertical"
BoxLayout:
orientation: "horizontal"
size_hint_y: None
height: self.minimum_height
Button:
text: "Logo"
size_hint: None, None
width: "80dp"
height: "40dp"
pos_hint: {'top': 1}
Button:
text: "Menu"
size_hint: 1, None
height: "40dp"
pos_hint: {'top': 1}
Button:
text: "Body"
Button:
text: "Footer"
size_hint: 1, None
height: "40dp"
这是由于 BoxLayout 提供的每个子部件都相等 space 但这里您更改了按钮的大小 BoxLayout.You 还需要更改 BoxLayout 的大小否则它会显示黑色。
<BoxExample@BoxLayout>:
orientation: "vertical"
BoxLayout:
orientation: "horizontal"
size_hint: None,None
size:root.size[0],"40dp"
Button:
text: "Logo"
size_hint: None, None
width: "80dp"
height: "40dp"
pos_hint: {'top': 1}
Button:
text: "Menu"
size_hint: 1, None
height: "40dp"
pos_hint: {'top': 1}
Button:
text: "Body"
Button:
text: "Footer"
size_hint: 1, None
height: "40dp"