Kivy RecycleView滞后

时间:2017-08-17 15:09:22

标签: python kivy

我想重新定义RecycleView(ScrollView)的on_touch_down方法,所以我从Kivy sources复制了这个方法,但是之后我的应用程序变得非常迟钝,它几乎停止响应鼠标。这是Kivy的一个错误还是我做错了什么?删除或评论on_touch_down方法可以解决问题,但我需要重新定义它。

Python 3.5,Kivy v1.10.0

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.recycleview import RecycleView


Builder.load_string('''
<RV>:
    viewclass: 'Label'
    RecycleBoxLayout:
        default_size: None, dp(56)
        default_size_hint: 1, None
        size_hint_y: None
        height: self.minimum_height
        orientation: 'vertical'
''')

class RV(RecycleView):
    def __init__(self, **kwargs):
        super(RV, self).__init__(**kwargs)
        self.data = [{'text': str(x)} for x in range(100)]

    def on_touch_down(self, touch):
        if self.dispatch('on_scroll_start', touch):     
            self._touch = touch
            return True

class TestApp(App):
    def build(self):
        return RV()

if __name__ == '__main__':
    TestApp().run()

1 个答案:

答案 0 :(得分:0)

您可能需要在覆盖on_touch_down

时调用super方法
    def on_touch_down(self, touch):
        if self.dispatch('on_scroll_start', touch):     
            self._touch = touch
            return True
        return super(RV, self).on_touch_down(touch)