尝试向下滚动垂直ScrollView和内部水平ScrollView时出现Kivy问题

时间:2019-08-07 14:00:31

标签: python kivy scrollview kivy-language

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

我尝试将horizo​​ntall 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()


1 个答案:

答案 0 :(得分:0)

我无法声称完全理解这种情况,但是似乎在另一个垂直ScrollView内的垂直ScrollView可以正常工作。因此,一种解决方法是将ScrollView类内的Custom允许垂直滚动(以及水平滚动)。为此,请将kvScrollView的{​​{1}}更改为:

Custom

为了使垂直滚动在上面起作用,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的大小提示。

相关问题