Search code examples
pythonkivyscrollviewdropdownbuildozer

Kivy 1.10.1 dropdown with scrollview can't scroll on touch


The code works perfectly with kivy 1.9.1 but not with kivy master or 1.10.1

code:

DropDown:
    auto_width: False
    id: colors
    size: (root.width, 100)
    ScrollView:
        bar_width: 5
        do_scroll_y: False
        do_scroll_x: True
        height: 100
        size_hint_y: None
        GridLayout:
            id: colors_scroll
            rows: 1
            spacing: 0
            width: self.minimum_width
            size_hint: None, None
            30Buttons:
                size_hint: None, None
                size: 100,100

Any help will be appreciated. Thank you!


Solution

  • The DropDown widget currently already has an inheritance of ScrollView.

    Try adding the following to ScrollView:

        effect_cls: "ScrollEffect"
        scroll_type: ['bars']
    

    Example

    main.py

    from kivy.uix.dropdown import DropDown
    from kivy.uix.button import Button
    from kivy.base import runTouchApp
    from kivy.lang import Builder
    
    Builder.load_string("""
    #:import Button kivy.uix.button.Button
    
    <CustomDropDown>:
        bar_width: 10
        effect_cls: "ScrollEffect"
        scroll_type: ['bars']
        bar_color: [1, 0, 0, 1]     # red color
        bar_inactive_color: [0, 0, 1, 1]    # blue color
    
        GridLayout:
            cols: 1
            size_hint_y: None
            height: self.minimum_size[1]
    
            on_parent:
                for i in range(1, 30): \
                    txt = "{0}".format(i); \
                    btn=Button(text=txt, size_hint_y=None, height=40); \
                    btn.bind(on_release=lambda btn: self.select(btn.text)); \
                    self.add_widget(btn)
    
    """)
    
    
    class CustomDropDown(DropDown):
        pass
    
    
    dropdown = CustomDropDown()
    mainbutton = Button(text='Hello', size_hint=(None, None))
    mainbutton.bind(on_release=dropdown.open)
    dropdown.bind(on_select=lambda instance, x: setattr(mainbutton, 'text', x))
    
    runTouchApp(mainbutton)
    

    Output

    DropDown - scroll bar inactive DropDown - scroll bar active