【问题标题】:how to add MDCard in ScrollView in KivyMD?如何在 KivyMD 的 ScrollView 中添加 MDCard?
【发布时间】:2022-03-28 00:11:40
【问题描述】:

我是 KivyMD 的新手,我有这个疑问。如何在 ScrollView 中添加 MDCard,就像我们使用列表一样。是否可以这样做。我参考了很多在线解决方案和网站,但没有一个问题与我的问题有关。请有人帮忙

【问题讨论】:

    标签: python python-3.x kivy kivymd


    【解决方案1】:

    我知道这个问题很老了,我在寻找其他答案时遇到了这个问题,我将把解决方案留在这里以防万一有人需要。

    到目前为止,MDCard 无法按原样添加到 ScrollView。

    要制作可滚动的卡片列表,您必须定义一个自定义类,研究以下代码:

    <CardItem@RelativeLayout>
        size_hint_y: None
        height: '150dp'
        radius: 50
        # for use in ScrollView
    
        MDCard:
            size_hint: .9, .9
            pos_hint: {'center_x': .5}
            Image:
                source: 'images/sample1.png'
            # you can make these cards as complex as you like
    

    现在

    ScrollView:
        MDList:
            CardItem
            CardItem:
                size_hint: .9, .9
                pos_hint: {'center_x': .5}
                Image:
                    source: 'images/sample2.png'
    

    请注意,定义的属性可以被覆盖,也可以添加新属性。

    希望这能回答你的问题!

    【讨论】:

    • 您也可以通过上述方法使用海拔和所有其他属性
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-23
    • 2021-07-24
    • 2020-12-22
    • 2021-11-24
    • 1970-01-01
    • 2021-10-03
    • 2021-06-28
    相关资源
    最近更新 更多