我对RecycleView
有问题。我想我不得不犯一个小错误,因为我还没有在谷歌上找到有同样问题的人。你知道吗
问题是,当我向我的RecycleView
列表添加新项目时,它们从底部出现,如下面的GIF所示:
这是我的代码摘录:
class SelectableButton(RecycleDataViewBehavior, Button):
index = None
def refresh_view_attrs(self, rv, index, data):
""" Catch and handle the view changes """
self.index = index
return super(SelectableButton, self).refresh_view_attrs(rv, index, data)
def on_press(self):
self.parent.parent.parent.chose_device(self.device)
print("Connecting to %d" % self.index)
class SelectableRecycleBoxLayout(FocusBehavior, LayoutSelectionBehavior, RecycleBoxLayout):
pass
class DeviceList(RecycleView):
def __init__(self, **kwargs):
super(DeviceList, self).__init__(**kwargs)
self.data = []
class DiscoveryForm(BoxLayout):
(...)
def new_device_discovered(self):
self.disc_list_prop.data = []
devices = self.discovery.get_discovered_devices()
for i, device in enumerate(devices):
self.disc_list_prop.data.append({'text': "Device " + device.mac, 'id': str(i), 'device': device})
def chose_device(self, text):
(...)
你知道吗约kv地址:
RootForm:
Label:
text: "Initialization"
<DiscoveryForm>:
orientation: "vertical"
platform_label_prop: platform_label
disc_list_prop: disc_list
Label:
id: platform_label
height: "40dp"
size_hint_y: None
text: "Discovery"
Button:
text: "Search for devices"
height: "100dp"
size_hint_y: None
on_press: root.start_searching()
DeviceList:
id: disc_list
Label:
size_hint_y: 1
Button:
text: "Go to driver"
size_hint_y: None
height: "50dp"
on_press: root.parent.show_driver_form()
<SelectableButton>:
<DeviceList>:
viewclass: 'SelectableButton'
SelectableRecycleBoxLayout:
orientation: 'vertical'
default_size_hint: 1, 1
我试图消除第一个按钮和第一个发现的设备按钮之间的差距,但没有差距。我也试过vlayout
,但没用。你知道吗
default_size_hint: 1, None
替换default_size_hint: 1, 1
size_hint_y: None
height: self.minimum_height
片段
相关问题 更多 >
编程相关推荐