【问题标题】:Boxlayouts in ScrollviewScrollview 中的框布局
【发布时间】:2016-06-07 12:57:24
【问题描述】:

我想请你帮忙。

link下的可滚动结构是我要生成的。

由于 Scrollview 只接受一个元素,我使用了 GridLayout。不知何故,我无法在 GridLayout 中放置任何 Boxlayout。

你能帮帮我吗?我做错了吗?我应该使用其他布局吗?如果是,是哪一个?

谢谢。

这是我的 .kv 文件的输出:http://imgur.com/etilRPg

这是结果,如果我将 cols:1 更改为 cols:2 :http://imgur.com/ihWla4Y

这是我在 .kv 文件中尝试的代码:

#:kivy 1.8.0
RootWidget:

    # import container
    container: container

    # fill container
    BoxLayout:
        id: container
        orientation: 'vertical'
        padding: 0
        spacing: 3

        ScrollView:
            size_hint: 1, 1
            pos_hint: {'center_x': .5, 'center_y': .5}


            GridLayout:
                cols: 1
                padding: 0
                spacing: 3
                size_hint: 1, None
                height: self.minimum_height
                do_scroll_x: False

                BoxLayout:
                    height: 260
                    orientation: 'horizontal'
                    canvas.before:
                        Color:
                            rgb: 0.7, 0.7, 0.9
                        Rectangle:
                            size: self.size
                            pos: self.pos


                BoxLayout:
                    height: 260
                    orientation: 'horizontal'
                    canvas.before:
                        Color:
                            rgb: 0.7, 0.7, 0.9
                        Rectangle:
                            size: self.size
                            pos: self.pos


                BoxLayout:
                    height: 260
                    orientation: 'horizontal'
                    canvas.before:
                        Color:
                            rgb: 0.7, 0.7, 0.9
                        Rectangle:
                            size: self.size
                            pos: self.pos

                #type
                Label:
                    height: 260
                    size_hint: 1, None
                    text: 'Typ'

                BoxLayout:
                    height: 260
                    orientation: 'horizontal'
                    canvas.before:
                        Color:
                            rgb: 0.7, 0.7, 0.9
                        Rectangle:
                            size: self.size
                            pos: self.pos

【问题讨论】:

    标签: python kivy kivy-language


    【解决方案1】:

    如果您想设置 heightwidth 或其他任何尺寸,您需要先在您要设置的小部件中做一些事情:

    size_hint: None, None
    

    这将禁用根据父级的大小和其他一些内容设置这些属性,即父级中的小部件数量(三个小部件 = 父级大小/每个 3),至少对于 BoxLayoutGridLayout 等布局。更多信息请查看docs

    如果您只想设置heightwidth 之一,也可以使用size_hint_x: Nonesize_hint_y: None 并让另一部分自动设置。

    【讨论】:

      猜你喜欢
      • 2013-09-25
      • 1970-01-01
      • 2016-07-17
      • 2019-01-08
      • 1970-01-01
      • 2010-12-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多