【发布时间】:2021-11-07 15:27:18
【问题描述】:
我正在尝试将 boxlayout 添加到已具有 boxlayout 的屏幕,但第二个 boxlayout 的内容一直覆盖第一个布局的内容。 我不认为这是我的缩进,是否有我遗漏的代码,或任何东西。
我当然希望第二个 boxlayout 的内容排在最后。我将非常感谢任何帮助,在此先感谢。
这是我的代码:
from kivy.lang import Builder
from kivymd.app import MDApp
from kivy.core.window import Window
Window.size = (300, 530)
KV = """
MDScreen:
MDBoxLayout:
orientation: 'vertical'
ScrollView:
MDGridLayout:
cols: 1
adaptive_height: True
padding: '10dp', '15dp'
spacing: '15dp'
MDCard:
orientation: 'vertical'
size_hint: 1, None
height: label1.height
# size: 280, 200
MDLabel:
id: label1
markup: True
padding: [15, 1]
size_hint_y: None
height: self.texture_size[1] + 2*self.padding[1]
text:
'''
[size=25][b]Ford[/b][/size]
[b][i]“Make every detail perfect and limit the number of details to perfect.[/b][/i]”
– Jack Dorsey\n
'''
MDCard:
orientation: 'vertical'
size_hint: 1, None
# size: 280, 200
height: label2.height
MDLabel:
id: label2
markup: True
padding: [15, 5]
size_hint_y: None
height: self.texture_size[1] + 2*self.padding[1]
text:
'''
[size=25][b]Ford[/b][/size]
[b][i]“Make every detail perfect and limit the number of details to perfect.[/b][/i]”
– Jack Dorsey\n
'''
MDCard:
orientation: 'vertical'
size_hint: 1, None
# size: 280, 200
height: label2.height
MDLabel:
id: label2
markup: True
padding: [15, 5]
size_hint_y: None
height: self.texture_size[1] + 2*self.padding[1]
text:
'''
[size=25][b]Ford[/b][/size]
[b][i]“Make every detail perfect and limit the number of details to perfect.[/b][/i]”
– Jack Dorsey\n
'''
MDBoxLayout:
orientation: 'vertical'
ScrollView:
MDGridLayout:
cols: 9
spacing: '10dp'
padding: ['10dp', '10dp']
MDCard:
ripple_behavior: True
orientation: 'vertical'
size_hint: None, None
size: "250dp", "180dp"
elevation: 15
radius: 15
caption: 'Hello dear'
Image:
allow_stretch: True
keep_ratio: False
size_hint_y: 1
source: "C:/Users/HP USER/Downloads/bella_baron.jpg"
MDCard:
ripple_behavior: True
orientation: 'vertical'
size_hint: None, None
size: "250dp", "180dp"
elevation: 15
radius: 15
caption: 'Hello dear'
Image:
allow_stretch: True
keep_ratio: False
size_hint_y: 1
source: "C:/Users/HP USER/Downloads/bella_baron.jpg"
MDCard:
ripple_behavior: True
orientation: 'vertical'
size_hint: None, None
size: "250dp", "180dp"
elevation: 15
radius: 15
caption: 'Hello dear'
Image:
allow_stretch: True
keep_ratio: False
size_hint_y: 1
source: "C:/Users/HP USER/Downloads/bella_baron.jpg"
"""
class Example(MDApp):
def build(self):
return Builder.load_string(KV)
Example().run()
【问题讨论】:
-
那么你在这里要做的是在第一个
MDBoxLayout之后,第二个将放在它下面,而不是它上面?只是问以防万一。 -
小部件的默认
pos是(0,0),因此您的两个MDBoxLayouts都将定位在(0,0)。您可以使用pos或pos_hint调整位置。 -
或者您也可以将所有
MDBoxLayouts 放入一个MDStackLayout并更改每个框布局的size_hint参数,但这很可能不是您想要的我想跨度> -
@Weebify 是的,我想将第二个放在它下面.... 请我希望您通过将 MDLayouts 放入单个 MDStacklayout 来向我展示您的意思的示例代码并更改 size_hint..
-
@JohnAnderson 我试着像你说的那样调整 pos_hint,但是 boxlayout 的大小变化不可接受,我该如何纠正这个问题,谢谢你的建议。