How do you scroll a GridLayout inside Kivy ScrollView?

前端 未结 2 615
天命终不由人
天命终不由人 2020-12-19 09:18

At the moment this is my kv code that is not scrollable:

BoxLayout:
    id: bl
    orientation: \'vertical\'
    padding: 10, 10
    row_default_height: \'48         


        
2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-19 09:38

    According to the documentation for ScrollView you have to disable at least one of the ScrollView's child size_hint:

    :
        layout_content: layout_content
        BoxLayout:
            id: bl
            orientation: 'vertical'
            padding: 10, 10
            row_default_height: '48dp'
            row_force_default: True
            spacing: 10, 10
            ScrollView:
                size: self.size
                GridLayout:
                    id: layout_content
                    size_hint_y: None
                    cols: 1
                    row_default_height: '20dp'
                    row_force_default: True
                    spacing: 0, 0
                    padding: 0, 0
    
                    Label:
                        text: "Lorem ipsum dolor sit amet"
    

    And bind the layout's size to adapt itself:

    # main.py
    
    class Controller(FloatLayout):
        layout_content=ObjectProperty(None)
    
        def __init__(self, **kwargs):
            super(Controller, self).__init__(**kwargs)
            self.layout_content.bind(minimum_height=self.layout_content.setter('height'))
    

提交回复
热议问题