尝试向下滚动垂直ScrollView和水平ScrollView时出现Kivy问题 [英] Problem with Kivy when trying to scrolldown vertical ScrollView with an horizontal ScrollView inside

查看:104
本文介绍了尝试向下滚动垂直ScrollView和水平ScrollView时出现Kivy问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Ok, so I'm building something with Kivy(1.11.1) and summarizing I have a ScrollView that scrolls vertically and inside it there are some others ScrollViews but these ones only scroll horizontally, the problem is that whenever I scroll the outer ScrollView down and the mouse position gets into the inner Horizontal ScrollViews the outer Scrollview stops scrolling down, it looks like once the mouse position collides with the horizontal scrollview the scroll behavior stops being sent to the outer ScrollView (vertical) so it stops scrolling down. What I want is something like the Netflix page, in which there are some scrollviews horizontally (My List, Series, Horror Movies, etc) that you can scroll to see more options but they're all inside an outer scrollview that scrolls vertically, of course that in Netflix when you scrolldown even if your mouse position get inside one of the horizontal scrollviews it still continue scrolling the outer ScrollView down.

我尝试将horizo​​ntall scrollview do_scroll_y设置为False,但问题仍然存在.除此之外.向上滚动就可以了

I've tried setting the horizontall scrollview do_scroll_y to False but the problem goes on. Besides that. Scrolling up works just fine

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()


推荐答案

我无法完全理解这种情况,但是似乎另一个ScrollView内的垂直ScrollView可以工作.因此,一种解决方法是将ScrollView放在您的Custom类中,以允许垂直滚动(以及水平滚动).为此,请将Custom内部的ScrollViewkv更改为:

I can't claim to understand this situation completely, but it seems that vertical ScrollView inside another vertical ScrollView works. So, a work around is to make the ScrollView inside your Custom class to allow vertical scrolling (along with the horizontal scrolling). To do this, change the kv for the ScrollView inside Custom to:

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大小提示.

In order for the vertical scrolling to work in the above, the height of the GridLayout must be larger than the height of the ScrollView, thus the 1.01 size hint.

这篇关于尝试向下滚动垂直ScrollView和水平ScrollView时出现Kivy问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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