了解 KivyMD 屏幕布局

Understanding KivyMD Screen Layouts

我想了解如何使用带有 ScrollView 的 GridLayout 和 BottomNavigation 来布局 KivyMD 屏幕。我的代码不起作用,因为 GridLayout 显示在 BottonNavigation 上,然后看不到。设置此布局的正确方法是什么?而且,通常有 KivyMD 屏幕布局的经验法则吗?谢谢

<MyScreen>:
name: 'myscreen'

ScrollView:
    orientation:'vertical'

    MDGridLayout:
        cols: 3
        adaptive_height: True
        padding: dp(4), dp(4)
        spacing: dp(4)

        etc.

BoxLayout:
    orientation:'vertical'

    MDBottomNavigation:
        panel_color: .2, .2, .2, 1

        MDBottomNavigationItem:
            name: 'left'
            text: 'Left'
            icon: 'chevron-left'

            MDLabel:
                text: 'Left'
                halign: 'center'
                font_style: 'Icon'

        MDBottomNavigationItem:
            name: 'right'
            text: 'Right'
            icon: 'chevron-right'

            MDLabel:
                text: 'Right'
                halign: 'center'
                font_style: 'Icon'
        etc.

布局 类 监视其子项的大小,并重新计算布局并在该大小发生变化时重新绘制。所以,我相信如果你的图片大小没有改变,那么只有那个图片会被更新。

kivy Builder 根据加载的kv 文件维护一组规则,因此这些规则是否来自单独的文件并不重要。我建议根据可维护性、可读性和逻辑分区等因素构建您的 kv 文件