我有一个应该有4种不同视图类型的循环视图,我真的不知道如何做到这一点我尝试在kv文件中使用相同的视图然后在视图类中的py我动态添加我真正想要的视图类型但它没有用。我的代码:
<FavsView>:
viewclass: 'FavBox'
RecycleBoxLayout:
default_size: None, 440
default_size_hint: 1, None
size_hint_y: None
height: self.minimum_height
orientation: 'vertical'
<FavBox>:
content: content
BoxLayout:
id: content
class FavsView(RecycleView):
boss = ObjectProperty()
diaryboxes = {}
musicboxes = {}
videoboxes = {}
boxes = {}
def __init__(self, **kwargs):
super(FavsView, self).__init__(**kwargs)
self.data = [{'name': 'test1', 'ind': 0, 'boss': self, 'typ': 'diary'},
{'name': 'test2', 'ind': 1, 'boss': self, 'typ': 'image'},
{'name': 'test3', 'ind': 2, 'boss': self, 'typ': 'music'},
{'name': 'test4', 'ind': 3, 'boss': self, 'typ': 'music'},
{'name': 'test5', 'ind': 4, 'boss': self, 'typ': 'video'},
{'name': 'test6', 'ind': 5, 'boss': self, 'typ': 'video'}
]
class FavBox(RecycleDataViewBehavior, BoxLayout):
boss = ObjectProperty()
loa = 0
content = ObjectProperty()
def __init__(self, **kwargs):
super(FavBox, self).__init__(**kwargs)
Clock.schedule_interval(self.up, 1)
def up(self, *args):
if self.loa == 0:
if self.typ == 'diary':
d = Factory.DiaryBox(ind=self.ind)
d.boss = self.boss
self.content.add_widget(d)
elif self.typ == 'image':
d = Factory.ImageBox()
d.boss = self.boss
self.content.add_widget(d)
elif self.typ == 'music':
d = Factory.MusicBox()
d.boss = self.boss
self.content.add_widget(d)
elif self.typ == 'video':
d = Factory.VideoBox()
d.boss = self.boss
self.content.add_widget(d)
self.loa = 1
答案 0 :(得分:0)
执行此操作的最佳方法是使用带有boxlayout的scrollview,然后将这些子项添加到此boxlayout