简体   繁体   English

带有滚动视图的Kivy 1.10.1下拉列表无法在触摸时滚动

[英]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 该代码可与kivy 1.9.1完美配合,但不适用于kivy master或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! 谢谢!

The DropDown widget currently already has an inheritance of ScrollView. DropDown小部件当前已经具有ScrollView的继承。

Try adding the following to ScrollView: 尝试将以下内容添加到ScrollView中:

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

Example

main.py 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-滚动条无效 下拉菜单-滚动条处于活动状态

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM