I have a nested horizontal scroll view inside a vertical scroll view, I followed many links, found nothing, I need a clear scrollview so that if I scroll nested horrizontal scrollview it will scroll without disturbing the parent vertical scrollview, and if I scroll the nested horrizontal scrollview vertically then only the parent vertical scroll view will scroll! any suggestions ? thanks in advance! (I want the scroll view to be same as any other modern app like facebook story horizontal scrollview,, etc..)
Python kivy : Nested scrollviews
607 views Asked by Fadi Sadaka At
2
There are 2 answers
0
On
I understand you and had the same problem trying to scroll horizontal scrollview vertically, which it should scroll the vertical parent scrollview instead.
I peeked into the source code of scrollview and found out the child scrollview stops propogating move event to parent when it receives touchmove.
Here's a demo of the solution (some hacks) that allows you to scroll horizontal scrollview vertically that affects parent scrollview.
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.lang.builder import Builder
from kivy.uix.scrollview import ScrollView
from kivy.properties import StringProperty
KV = """
<SomeText>
id: some_text
orientation: 'horizontal'
ScrollText:
Label:
text: some_text.text
max_lines: 1
halign: 'left'
padding_x: 20
font_size: some_text.height
width: self.texture_size[0]
size_hint_x: None
<ScrollText>
bar_color: (1,1,1,1)
bar_width: 1
<VerticalScroll>
some_text_list: some_text_list
GridLayout:
id: some_text_list
cols: 1
size_hint_y: None
row_default_height: 80
row_force_default: True
height: self.minimum_height
"""
class SomeText(BoxLayout):
text = StringProperty()
class ScrollText(ScrollView):
# pass y-move event to parent instead of stopping
def on_scroll_move(self, touch):
super().on_scroll_move(touch)
touch.ud['sv.handled']['y'] = False
class VerticalScroll(ScrollView):
def __init__(self, texts, **kwargs):
super().__init__(**kwargs)
for text in texts:
self.some_text_list.add_widget(SomeText(text=text))
# prevent stuck on overscroll
def on_scroll_stop(self, touch, check_children=True):
super().on_scroll_stop(touch, check_children=False)
if __name__ == "__main__":
class TestApp(App):
def build(self):
Builder.load_string(KV)
long_text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
texts = [long_text for _ in range(20)]
return VerticalScroll(texts)
TestApp().run()
This is how you can achieve what you are looking for.
Use KivyMD to get material design for your app. https://kivymd.readthedocs.io/en/latest/index.html
Then try this
scrollview.py
scrolltwo.kv
Output