下記コードで行っていることは
- RecycleView内でRecycleBoxLayoutを100個生成、配列に入れる。
- 1秒後に配列内のRecycleBoxLayoutにLabelを追加する。
です。
以下の問題があり、これらの解決法を教えてください。
- スクロールができません。一応スクロールバーは生成した分だけの長さにはなっているようです。
- add_widgetにも以下のようなエラーが発生します。以下のエラーでは何かの引数が足りていないようなのですが、それが何かはわかっていません。
TypeError: add_widget() takes at most 3 arguments (4 given)
正直、RecycleViewはやめたいです。
何か別な良い省メモリ化についてのkivyリファレンス等があれば教えてください。
python
1from kivy.app import App 2from kivy.lang import Builder 3from kivy.uix.recycleview import RecycleView 4from kivy.uix.recycleview.views import RecycleDataViewBehavior 5from kivy.uix.label import Label 6from kivy.properties import BooleanProperty, ListProperty 7from kivy.uix.recycleboxlayout import RecycleBoxLayout 8from kivy.uix.behaviors import FocusBehavior 9from kivy.uix.recycleview.layout import LayoutSelectionBehavior 10from kivy.clock import Clock 11 12Builder.load_string(''' 13<SelectableGrid>: 14 size_hint: 1, None 15 height: 30 16 orientation: 'vertical' 17 canvas.before: 18 Color: 19 rgba: root.b 20 Rectangle: 21 pos: self.pos 22 size: self.size 23 24<RV>: 25 viewclass: 'SelectableGrid' 26 SelectableRecycleBoxLayout: 27 default_size: None, dp(56) 28 default_size_hint: 1, None 29 size_hint_y: None 30 height: self.minimum_height 31 orientation: 'vertical' 32 multiselect: True 33 touch_multiselect: True 34''') 35 36 37class SelectableRecycleBoxLayout(FocusBehavior, LayoutSelectionBehavior, 38 RecycleBoxLayout): 39 ''' Adds selection and focus behaviour to the view. ''' 40 41grids = [] 42class SelectableGrid(RecycleDataViewBehavior, RecycleBoxLayout, RecycleView): 43 ''' Add selection support to the Label ''' 44 a = 0 45 b = ListProperty([1,1,1,1]) 46 def refresh_view_attrs(self, rv, index, data): 47 ''' Catch and handle the view changes ''' 48 x = self.a % 2 49 if x == 0 : 50 self.b = [0,0,1,1] 51 else: 52 self.b = [1,0,1,1] 53 grids.append(self) 54 return super(SelectableGrid, self).refresh_view_attrs( 55 rv, index, data) 56 57 58 59class RV(RecycleView): 60 def __init__(self, **kwargs): 61 super(RV, self).__init__(**kwargs) 62 self.data = [ 63 { 64 'a': x 65 } for x in range(100) 66 ] 67 68 69 70def my_callback(dt): 71 for i in grids: 72 i.add_widget(Label(text = 'Hello')) 73Clock.schedule_once(my_callback, 2) 74 75 76 77class TestApp(App): 78 def build(self): 79 return RV() 80 81if __name__ == '__main__': 82 TestApp().run()
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。