【问题标题】:How can I adjust the size of a KivyMD Tabs' content?如何调整 KivyMD 标签内容的大小?
【发布时间】:2019-10-20 17:28:23
【问题描述】:

我正在尝试使用 KivyMD 构建三个选项卡,但是当我向每个 MDTabsBase 添加内容时,内容总是占用相同的空间。我尝试了很多改变它的大小,所以内容占据了整个盒子,但只是不起作用。

下面是内容的样子:

还有代码:

Screen:
    name: 'itemscad_food'
    BoxLayout:
        id: boxcad
        orientation: 'vertical'
        MDToolbar:
            id: toolcad
            title: "Item Register"
            md_bg_color: app.theme_cls.primary_color
            anchor_title: 'justify'
            left_action_items: [['menu-left', lambda x: app.back_button()]]
        BoxLayout:
            id: tabox
            orientation: 'vertical'
            MDTabs:
                id: itemstab
                tab_display_mode: 'text'            

                MDTabsBase:
                    id: ingr_tab
                    name: 'ingredients'
                    text: "Ingredientes"                                                

                MDTabsBase:
                    id: prod_tab
                    name: 'products'
                    text: "Products"
                    MyLabel:
                        text: 'Strawberry Cake'
                    MyLabel:
                        text: 'Chocolate Cake'

                MDTabsBase:
                    id: pack_tab
                    name: 'packs'
                    text: "Pacotes"

是的,我只为此使用 KV 语言。我正在上面构建大部分应用程序的布局,到目前为止一切都很好,除了这个:/

我也尝试过另一种方式:

  • 与 MDTabs 类分开构建选项卡内容,但这样我似乎无法找到为每个选项卡制作不同内容的方法。

这是另一种方式的样子:

还有代码:

    Screen: 
        name: 'itemscad_food'
        BoxLayout:
            id: boxcad
            orientation: 'vertical'
            MDToolbar:
                id: toolcad
                title: "Item Register"
                md_bg_color: app.theme_cls.primary_color
                anchor_title: 'justify'
                left_action_items: [['menu-left', lambda x: app.back_button()]]
            BoxLayout:
                id: tabox
                orientation: 'vertical'
                MDTabs:
                    id: itemstab
                    tab_display_mode: 'text'            

                    MDTabsBase:
                        id: ingr_tab
                        name: 'ingredients'
                        text: "Ingredientes"                                                

                    MDTabsBase:
                        id: prod_tab
                        name: 'products'
                        text: "Products"

                    MDTabsBase:
                        id: pack_tab
                        name: 'packs'
                        text: "Pacotes"

            FloatLayout:       
                BoxLayout:
                    id: listbox
                    size_hint_y: None
                    height: boxcad.height - (toolcad.height + itemstab.tab_bar_height)
                    orientation: 'vertical'
                    ScrollView:
                        do_scroll_x: False
                        MDList:     
                            OneLineRightIconListItem:
                                text: 'Strawberry Cake'
                                MyListDeleteIcon:
                                    icon: 'trash-can'
                            OneLineRightIconListItem:
                                text: 'Chocolate Cake'
                                MyListDeleteIcon:
                                    icon: 'trash-can'
                            OneLineRightIconListItem:
                                text: 'Vanilla Cake'
                                MyListDeleteIcon:
                                    icon: 'trash-can'
                            ...

谁能给我一些想法?

对于任何错误,我深表歉意,因为我仍然习惯于编码 xD

还是谢谢!!!

【问题讨论】:

    标签: python kivy kivy-language


    【解决方案1】:

    在你的 python 文件中创建一个继承自 FloatLayout 和 MDTabsBase 的类,然后你可以将你的标签放在你想要的任何位置enter code here

    `从 kivymd.uix.tab 导入 MDTabsBase 从 kivymd.uix.floatlayout 导入 FloatLayout

    类 MyTab(FloatLayout,MDTabsBase):

        pass
    

    类 MyTab1(FloatLayout,MDTabsBase):

        pass
    

    `

    使用 Tab 下的 kivy 文件访问该类,然后赋予它您喜欢的漂亮外观

    【讨论】:

      【解决方案2】:

      您可以使用选项allow_stretch 并在MDTabs 下将其设置为True。抱歉,我似乎无法缩进代码。

      MDTabs:
          id: itemstab
          tab_display_mode: 'text'
          allow_stretch: True
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-01-06
        • 1970-01-01
        • 1970-01-01
        • 2014-10-14
        • 2021-07-26
        • 1970-01-01
        • 2013-08-10
        • 2023-01-04
        相关资源
        最近更新 更多