【问题标题】:Kivy RecycleView lagsKivy RecycleView 滞后
【发布时间】:2017-08-17 15:09:21
【问题描述】:

我想重新定义 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()

【问题讨论】:

    标签: python kivy


    【解决方案1】:

    您可能需要在覆盖 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)
    

    【讨论】:

    • 不,没有帮助。
    • 好吧。实际上它是工作,正确的代码是:def on_touch_down(self, touch): if super(RV, self).on_touch_down(touch): self._touch = touch return True
    • 嗯,这取决于具体情况和你想做什么,很高兴你想通了 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-15
    • 2017-10-28
    • 1970-01-01
    • 1970-01-01
    • 2019-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多