如何在Kivy ScrollView中滚动GridLayout? [英] How do you scroll a GridLayout inside Kivy ScrollView?

查看:108
本文介绍了如何在Kivy ScrollView中滚动GridLayout?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,这是我的kv代码,无法滚动:

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

BoxLayout:
    id: bl
    orientation: 'vertical'
    padding: 10, 10
    row_default_height: '48dp'
    row_force_default: True
    spacing: 10, 10

    GridLayout:
        id: layout_content
        cols: 1
        row_default_height: '20dp'
        row_force_default: True
        spacing: 0, 0
        padding: 0, 0

        Label:
            text: 'You don''t have any downloads. Please add new download from Home screen'

如何使以上kv代码可滚动?我知道Kivy ScrollView仅接受一个孩子,并且我已经使GridLayout成为新ScrollView的孩子.但这不起作用.有什么建议吗?

How do you make the above kv code scrollable? I know that Kivy ScrollView only accept one child, and I have already make GridLayout to be child of a new ScrollView. But it's not working. Any suggestion?

推荐答案

根据

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

<Controller>:
    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'))

这篇关于如何在Kivy ScrollView中滚动GridLayout?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆