【问题标题】:KivyMD - why is the MDList just on half of the screenKivyMD - 为什么 MDList 只是在屏幕的一半
【发布时间】:2021-09-08 07:59:59
【问题描述】:

我想使用 ButtonNavigation + MDList,但该列表只能在屏幕的一半上看到(见屏幕截图)。我可以在整个屏幕上显示列表吗?

<CreateScreen>
    name: "create_screen"
    BoxLayout:
        orientation: "vertical"
        ScrollView:
            MDList:
                TwoLineAvatarIconListItem:
                    id: list1
                    text: "Date"
                    secondary_text: "Time"
                    IconLeftWidget:
                        icon: "github"
                        on_release: print("Hello")
                    IconRightWidget:
                        icon: "clock"


        MDBottomNavigation:
            MDBottomNavigationItem:
                name: 'screen 1'
                text: 'Back'
                icon: "arrow-left"
                on_tab_release: root.manager.current = "main_screen"


            MDBottomNavigationItem:
                name: 'screen 2'
                text: 'ADD'
                icon: "calendar-plus"
                on_tab_release: root.create_new_date_picker()

Screenshot - List is just on half screen

【问题讨论】:

    标签: kivy kivy-language kivymd


    【解决方案1】:

    您可以在每个底部项目下添加内容并修复它,您也可以使用 RecycleView 优化内存,使用代码:

    <CreateScreen>
        name: "create_screen"
        BoxLayout:
            orientation: 'vertical'
            #do not put the content of your screen or scrollview here,
            #because the bottom toolbar has its own screen body
    
    
            MDBottomNavigation:
                MDBottomNavigationItem:
                    name: 'screen 1'
                    text: 'Back'
                    icon: "arrow-left"
                    #on_tab_release: root.manager.current = "main_screen"
                    ScrollView:
                        MDList:
                            TwoLineAvatarIconListItem:
                                id: list1
                                text: "jbsidis"
                                secondary_text: "Time"
                                IconLeftWidget:
                                    icon: "pencil"
                                    on_release: print("Hello")
                                IconRightWidget:
                                    icon: "clock"
                            TwoLineAvatarIconListItem:
                                canvas:
                                    Color:
                                        rgba: [0,1,0,.3]
                                    Rectangle:
                                        pos: self.pos
                                        size: self.size
                                id: list1
                                text: "El Salvador"
                                secondary_text: "Time"
                                IconLeftWidget:
                                    icon: "pencil"
                                    on_release: print("Hello")
                                IconRightWidget:
                                    icon: "clock"
                            TwoLineAvatarIconListItem:
                                id: list1
                                markup: True
                                text: "[i]New promotions"
                                secondary_text: "Time"
                                IconLeftWidget:
                                    icon: "pencil"
                                    on_release: print("Hello")
                                IconRightWidget:
                                    icon: "clock"
                            TwoLineAvatarIconListItem:
                                canvas:
                                    Color:
                                        rgba: [0,0,1,.3]
                                    Rectangle:
                                        pos: self.pos
                                        size: self.size
                                id: list1
                                text: "jbsidis"
                                secondary_text: "Time"
                                IconLeftWidget:
                                    icon: "pencil"
                                    on_release: print("Hello")
                                IconRightWidget:
                                    icon: "clock"
                            TwoLineAvatarIconListItem:
                                id: list1
                                text: "jbsidis"
                                secondary_text: "Time"
                                IconLeftWidget:
                                    icon: "pencil"
                                    on_release: print("Hello")
                                IconRightWidget:
                                    icon: "clock"
                            TwoLineAvatarIconListItem:
                                id: list1
                                text: "jbsidis"
                                secondary_text: "Time"
                                IconLeftWidget:
                                    icon: "pencil"
                                    on_release: print("Hello")
                                IconRightWidget:
                                    icon: "clock"
                            TwoLineAvatarIconListItem:
                                id: list1
                                text: "jbsidis"
                                secondary_text: "Time"
                                IconLeftWidget:
                                    icon: "pencil"
                                    on_release: print("Hello")
                                IconRightWidget:
                                    icon: "clock"
                            TwoLineAvatarIconListItem:
                                id: list1
                                text: "jbsidis"
                                secondary_text: "Time"
                                IconLeftWidget:
                                    icon: "pencil"
                                    on_release: print("Hello")
                                IconRightWidget:
                                    icon: "clock"
                            TwoLineAvatarIconListItem:
                                id: list1
                                text: "jbsidis"
                                secondary_text: "Time"
                                IconLeftWidget:
                                    icon: "pencil"
                                    on_release: print("Hello")
                                IconRightWidget:
                                    icon: "clock"
    
    
                MDBottomNavigationItem:
                    name: 'screen 2'
                    text: 'ADD'
                    icon: "calendar-plus"
                    #on_tab_release: root.create_new_date_picker()
                    ScrollView:
                        MDList:
                            TwoLineAvatarIconListItem:
                                id: list1
                                text: "jbsidis"
                                secondary_text: "Time"
                                IconLeftWidget:
                                    icon: "star"
                                    on_release: print("Hello")
                                IconRightWidget:
                                    icon: "clock"
                            TwoLineAvatarIconListItem:
                                canvas:
                                    Color:
                                        rgba: [0,1,0,.3]
                                    Rectangle:
                                        pos: self.pos
                                        size: self.size
                                id: list1
                                text: "jbsidis"
                                secondary_text: "Time"
                                IconLeftWidget:
                                    icon: "star"
                                    on_release: print("Hello")
                                IconRightWidget:
                                    icon: "clock"
                            TwoLineAvatarIconListItem:
                                id: list1
                                text: "jbsidis"
                                secondary_text: "Time"
                                IconLeftWidget:
                                    icon: "star"
                                    on_release: print("Hello")
                                IconRightWidget:
                                    icon: "clock"
                            TwoLineAvatarIconListItem:
                                canvas:
                                    Color:
                                        rgba: [0,0,1,.3]
                                    Rectangle:
                                        pos: self.pos
                                        size: self.size
                                id: list1
                                text: "jbsidis"
                                secondary_text: "Time"
                                IconLeftWidget:
                                    icon: "star"
                                    on_release: print("Hello")
                                IconRightWidget:
                                    icon: "clock"
                            TwoLineAvatarIconListItem:
                                id: list1
                                text: "jbsidis"
                                secondary_text: "Time"
                                IconLeftWidget:
                                    icon: "pencil"
                                    on_release: print("Hello")
                                IconRightWidget:
                                    icon: "clock"
                            TwoLineAvatarIconListItem:
                                id: list1
                                text: "jbsidis"
                                secondary_text: "Time"
                                IconLeftWidget:
                                    icon: "pencil"
                                    on_release: print("Hello")
                                IconRightWidget:
                                    icon: "clock"
                            TwoLineAvatarIconListItem:
                                id: list1
                                text: "jbsidis"
                                secondary_text: "Time"
                                IconLeftWidget:
                                    icon: "pencil"
                                    on_release: print("Hello")
                                IconRightWidget:
                                    icon: "clock"
                            TwoLineAvatarIconListItem:
                                id: list1
                                text: "jbsidis"
                                secondary_text: "Time"
                                IconLeftWidget:
                                    icon: "pencil"
                                    on_release: print("Hello")
                                IconRightWidget:
                                    icon: "clock"
                            TwoLineAvatarIconListItem:
                                id: list1
                                text: "jbsidis"
                                secondary_text: "Time"
                                IconLeftWidget:
                                    icon: "pencil"
                                    on_release: print("Hello")
                                IconRightWidget:
                                    icon: "clock"
    

    图片如下:

    【讨论】:

    • 谢谢,但它对我不起作用,因为用户可以更改列表。所以我不能有多个列表。难道没有别的办法了吗?还是我应该使用其他东西作为按钮导航?
    • 我可以把 MDBottomNavigation 做得小到 MDList 在整个屏幕上吗?
    • 是的,有几种方法可以做到这一点,如果我们使用“on_scroll_move”,我认为最好的方法之一可能是动画 MDBottom 栏以隐藏自身(类似于 VLC Android确实),这是一个很好的问题
    【解决方案2】:

    我在 MDBottomNaviagtion 中添加了以下内容

    MDBottomNavigation:
                height: self.minimum_height
                size_hint: 1, 0.1
    

    现在它只使用它需要的空间。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-07
      • 1970-01-01
      • 2018-12-10
      • 1970-01-01
      • 1970-01-01
      • 2020-02-22
      • 1970-01-01
      相关资源
      最近更新 更多