【问题标题】:Problem with Kivy when trying to scrolldown vertical ScrollView with an horizontal ScrollView inside尝试向下滚动带有水平 ScrollView 的垂直 ScrollView 时出现 Kivy 问题
【发布时间】:2019-08-07 14:00:31
【问题描述】:

好的,所以我正在使用 Kivy(1.11.1) 构建一些东西,并总结一下我有一个垂直滚动的 ScrollView,其中还有一些其他 ScrollView,但这些仅水平滚动,问题是每当我滚动外部 ScrollView 向下并且鼠标位置进入内部 Horizo​​ntal ScrollViews 外部 Scrollview 停止向下滚动,看起来一旦鼠标位置与水平滚动视图发生冲突,滚动行为就会停止发送到外部 ScrollView(垂直),因此它停止向下滚动.我想要的是类似于 Netflix 页面的东西,其中有一些水平滚动视图(我的列表、系列、恐怖电影等),您可以滚动以查看更多选项,但它们都在垂直滚动的外部滚动视图中,当然,在 Netflix 中,当您向下滚动时,即使您的鼠标位置进入水平滚动视图之一,它仍然会继续向下滚动外部 ScrollView。

我尝试将水平滚动视图 do_scroll_y 设置为 False,但问题仍然存在。除此之外。向上滚动效果很好

from kivy.app import App
from kivy.lang.builder import Builder
from kivy.uix.boxlayout import BoxLayout

Builder.load_string(
'''
<ScrollApp>:
    ScrollView:
        bar_width: 10
        scroll_type: ['bars', 'content']

        BoxLayout:
            id: content
            orientation: 'vertical'
            size_hint: 1, None
            height: self.minimum_height
            padding: 22, 0, 22, 50
            spacing: 50
            canvas:
                Color:
                    rgba: .15, .15, .15, .9
                Rectangle:
                    size: self.size
                    pos: self.pos
            Button:
                size_hint: None, None
                width: 100
                height: 100
                on_press: print('pressed')
            # "ScrollViews containers"
            Custom
            Custom
            Custom
            Custom

<Custom@BoxLayout>:
    orientation: 'vertical'
    size_hint: 1, None
    height: self.minimum_height
    Label:
        size_hint: None, None
        size: self.texture_size
        id: label
        font_size: 20
    ScrollView:
        size_hint: 1, None
        height: 150
        do_scroll: True, False

        on_scroll_start: print('scrolling. but why?')
        GridLayout:
            id: grid
            size_hint: None, None
            size: self.minimum_width, 150
            spacing: 5
            cols: 3
            Button:
                size_hint: None, None
                size: 400, 150
            Button:
                size_hint: None, None
                size: 400, 150
            Button:
                size_hint: None, None
                size: 400, 150
''' )

class ScrollApp(BoxLayout):
    pass

class Test(App):
    def build(self):
        return ScrollApp()

Test().run()


【问题讨论】:

  • 如果您发布minimal reproducible example,您更有可能获得一些帮助。
  • 好的,谢谢。现在它确实有效
  • 如果您找到了答案,您应该将其发布(回答您自己的问题)以供可能遇到这种情况的其他人使用。
  • 对不起,我的意思是我发布的代码现在确实像一个最小的可重现示例一样工作。虽然我没有找到问题的答案

标签: python kivy scrollview kivy-language


【解决方案1】:

我不能声称完全理解这种情况,但似乎垂直ScrollView 在另一个垂直ScrollView 内有效。因此,一种解决方法是在 Custom 类中创建 ScrollView 以允许垂直滚动(以及水平滚动)。为此,请将Custom 内的ScrollViewkv 更改为:

ScrollView:
    size_hint: 1, None
    height: 150
    do_scroll: True, True  # allow vertical scrolling also

    on_scroll_start: print('scrolling. but why?')
    GridLayout:
        id: grid
        size_hint: None, 1.01   # height must be slightly greater than ScrollView height
        width: self.minimum_width

为了使垂直滚动在上面起作用,GridLayout 的高度必须大于ScrollView 的高度,因此1.01 的大小提示。

【讨论】:

  • 嗯,这是一个奇怪的行为。真的很感谢你的帮助,真的,非常感谢你
  • 哦,如果你有时间可以看看我在同一个项目中遇到的另一个问题:stackoverflow.com/questions/57417345/…
猜你喜欢
  • 2020-09-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-02
  • 1970-01-01
  • 2018-10-02
  • 2011-11-08
  • 2015-11-30
相关资源
最近更新 更多