尝试使用内部水平滚动视图向下滚动垂直滚动视图时,Kivy 出现问题
Problem with Kivy when trying to scrolldown vertical ScrollView with an horizontal ScrollView inside
好的,所以我正在用 Kivy(1.11.1) 构建一些东西并总结我有一个垂直滚动的 ScrollView 并且在它里面有一些其他的 ScrollView 但这些只能水平滚动,问题是每当我向下滚动外部 ScrollView,鼠标位置进入内部 Horizontal ScrollViews,外部 ScrollView 停止向下滚动,看起来一旦鼠标位置与水平滚动视图发生碰撞,滚动行为就会停止发送到外部 ScrollView(垂直),因此它会停止向下滚动。我想要的是类似于 Netflix 页面的东西,其中有一些水平滚动视图(我的列表、系列、恐怖电影等),您可以滚动它们以查看更多选项,但它们都在垂直滚动的外部滚动视图中,当然,在 Netflix 中,当您向下滚动时,即使您的鼠标位置进入水平滚动视图之一,它仍然会继续向下滚动外部 ScrollView。
我试过将 horizontal 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()
我不能声称完全理解这种情况,但似乎在另一个垂直 ScrollView
中的垂直 ScrollView
有效。因此,解决方法是在 Custom
class 中设置 ScrollView
以允许垂直滚动(以及水平滚动)。为此,将 Custom
中 ScrollView
的 kv
更改为:
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
大小提示。
好的,所以我正在用 Kivy(1.11.1) 构建一些东西并总结我有一个垂直滚动的 ScrollView 并且在它里面有一些其他的 ScrollView 但这些只能水平滚动,问题是每当我向下滚动外部 ScrollView,鼠标位置进入内部 Horizontal ScrollViews,外部 ScrollView 停止向下滚动,看起来一旦鼠标位置与水平滚动视图发生碰撞,滚动行为就会停止发送到外部 ScrollView(垂直),因此它会停止向下滚动。我想要的是类似于 Netflix 页面的东西,其中有一些水平滚动视图(我的列表、系列、恐怖电影等),您可以滚动它们以查看更多选项,但它们都在垂直滚动的外部滚动视图中,当然,在 Netflix 中,当您向下滚动时,即使您的鼠标位置进入水平滚动视图之一,它仍然会继续向下滚动外部 ScrollView。
我试过将 horizontal 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()
我不能声称完全理解这种情况,但似乎在另一个垂直 ScrollView
中的垂直 ScrollView
有效。因此,解决方法是在 Custom
class 中设置 ScrollView
以允许垂直滚动(以及水平滚动)。为此,将 Custom
中 ScrollView
的 kv
更改为:
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
大小提示。