KivyMD MDCardpost不显示多列

时间:2019-09-13 05:32:38

标签: python kivy

我正在尝试使用KivyMD并坚持使用MDCardPost。

成功:我已经在Scroll的GridLayout中添加了MDCardPost。一张卡片显示在1列中。

需要帮助::当我在cols:2中更改GridLayout时,MDCardPost仍然在一行中显示一张卡片。

.kv文件片段

<windowone>:
    name:'winone'
    BoxLayout:
        orientation: 'vertical'
        spacing: dp(5)

        ScrollView:
            id: scroll
            size_hint: 1, .5
            do_scroll_x: False

            GridLayout:
                id: gri_card
                cols:2
                spacing: dp(5)
                padding: dp(5)
                size_hint: None,None
                height: self.minimum_height

.py文件摘要

class windowone(Screen):
    cards_created = False

    def on_pre_enter(self):
        def callback_for_menu_items(text_item):
            toast(text_item)

        def callback(instance, value):
            if value and isinstance(value, int):
                toast('Set like in %d stars' % value)
            elif value and isinstance(value, str):
                toast('Repost with %s ' % value)
            elif value and isinstance(value, list):
                toast(value[1])
            else:
                toast('Delete post %s' % str(instance))

        instance_grid_card = self.ids.gri_card
        buttons = ['facebook', 'vk', 'twitter']
        menu_items = [
            {'viewclass': 'MDMenuItem',
             'text': 'Example item %d' % i,
             'callback': callback_for_menu_items}
            for i in range(2)
        ]

        if not self.cards_created:
            self.cards_created = True

            instance_grid_card.add_widget(
                MDCardPost(right_menu=menu_items,
                    source="assets/kitten-1049129_1280.png",
                    tile_text="Little Baby",
                    tile_font_style="H5",
                    text_post="This is my favorite cat. He's only six months "
                              "old. He loves milk and steals sausages :) "
                              "And he likes to play in the garden.",
                    with_image=True, swipe=True, callback=callback,
                    ))
            instance_grid_card.add_widget(
                MDCardPost(right_menu=menu_items,
                    source="assets/kitten-1049129_1280.png",
                    tile_text="Little Baby",
                    tile_font_style="H5",
                    text_post="This is my favorite cat. He's only six months "
                              "old. He loves milk and steals sausages :) "
                              "And he likes to play in the garden.",
                    with_image=True, swipe=True, callback=callback,
                    ))
            instance_grid_card.add_widget(
                MDCardPost(right_menu=menu_items,
                    source="assets/kitten-1049129_1280.png",
                    tile_text="Little Baby",
                    tile_font_style="H5",
                    text_post="This is my favorite cat. He's only six months "
                              "old. He loves milk and steals sausages :) "
                              "And he likes to play in the garden.",
                    with_image=True, swipe=True, callback=callback,
                    ))
            instance_grid_card.add_widget(
                MDCardPost(right_menu=menu_items,
                    source="assets/kitten-1049129_1280.png",
                    tile_text="Little Baby",
                    tile_font_style="H5",
                    text_post="This is my favorite cat. He's only six months "
                              "old. He loves milk and steals sausages :) "
                              "And he likes to play in the garden.",
                    with_image=True, swipe=True, callback=callback,
                    ))
            instance_grid_card.add_widget(
                MDCardPost(right_menu=menu_items,
                    source="assets/kitten-1049129_1280.png",
                    tile_text="Little Baby",
                    tile_font_style="H5",
                    text_post="This is my favorite cat. He's only six months "
                              "old. He loves milk and steals sausages :) "
                              "And he likes to play in the garden.",
                    with_image=True, swipe=True, callback=callback,
                    ))

0 个答案:

没有答案