我想重新定义RecycleView的on_touch_down方法(ScrollView),所以我从Kivy sources复制了这个方法,但是在那之后我的应用变得非常迟缓,它几乎停止了对鼠标的响应。是Kivy中的bug,还是我做错了什么?删除或注释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()
发布于 2017-08-17 22:31:49
您可能需要在重写on_touch_down时调用超级方法
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)
https://stackoverflow.com/questions/45738817
复制