Kivy在尝试用水平滚动视图向下滚动垂直滚动视图时出现问题

2024-04-16 17:20:18 发布

您现在位置:Python中文网/ 问答频道 /正文

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

我尝试将水平滚动视图do\u scroll\u 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()



Tags: fromselfnone视图sizecustom水平button
1条回答
网友
1楼 · 发布于 2024-04-16 17:20:18

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

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大小提示。你知道吗

相关问题 更多 >