【发布时间】:2021-11-02 09:27:55
【问题描述】:
我想设置mdcard height 使其适合mdlabel,也许不需要我手动设置 mdcard 大小。
请问我该怎么做..在此先感谢..
为了更好地理解这里有一个示例代码:
from kivy.lang import Builder
from kivymd.app import MDApp
from kivy.core.window import Window
Window.size = (300, 530)
KV = """
MDBoxLayout:
orientation: 'vertical'
ScrollView:
MDGridLayout:
cols: 1
adaptive_height: True
padding: '10dp', '15dp'
spacing: '15dp'
MDCard:
orientation: 'vertical'
size_hint: None, None
size: 280, 200
MDLabel:
markup: True
padding: [15, 15]
text:
'''
[size=25][b]Ford[/b][/size]
If mdlabel text becomes too many to fit into the specified mdcard size,\n
the text overslaps other things closeby..\n
So my question: How do I set MDCard height to automatically\n
adjusts accordingly to the height/size of widgets inside of it.\n
Thanks in Advance!!
'''
MDCard:
orientation: 'vertical'
size_hint: None, None
size: 280, 200
MDLabel:
markup: True
padding: [15, 15]
text:
'''
[size=25][b]Ford[/b][/size]
If mdlabel text becomes too many to fit into the specified mdcard size,\n
the text overslaps other things closeby..\n
So my question: How do I set MDCard height to automatically\n
adjusts accordingly to the height/size of widgets inside of it.\n
Thanks in Advance!!
'''
"""
class Example(MDApp):
def build(self):
return Builder.load_string(KV)
Example().run()
就像上面的代码一样,如果 mdlabel 文本变得太多而无法适应指定的 mdcard 大小,则文本会覆盖附近的其他内容。 所以我的问题是:如何将 MDCard 高度设置为根据其中的小部件的高度/大小自动调整。 提前致谢!!
【问题讨论】:
标签: python-3.x kivy kivymd