是否可以在Kivy列表视图的行之间应用垂直填充?我已经尝试修改列表视图和gridlayout上的kv文件填充无济于事。
+++++++
+ Row +
+++++++
+ Pad +
+++++++
+ Row +
+++++++
答案 0 :(得分:2)
以下内容将使用ListAdapter和list_items_arg_converter在ListView项之间添加填充,您可以在其中修改ListItem的外观。它不会更改底层GridLayout的填充,只会更改项目的高度。
希望这有帮助,
干杯
[Kivy] v1.9.1
[Python] v2.7.11(v2.7.11:6d1b6a68f775,2015年12月5日,20:32:19)[MSC v.1500 32 bit(Intel)]
from kivy.uix.boxlayout import BoxLayout
from kivy.adapters.dictadapter import ListAdapter
from kivy.uix.button import Button
from kivy.uix.listview import ListView, ListItemButton
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.app import App
from random import randint
class MyApp(App):
items = 20
pad = 20
space = 20
text_border = 10
def build(self):
mainlayout = BoxLayout(orientation = 'vertical')
self.list_adapter = ListAdapter(data = ["Item #{0}".format(i) for i in range(self.items)], cls = ListItemButton,
args_converter=self.list_item_args_converter, sorted_keys = [])
self.list_view = ListView(adapter=self.list_adapter, size_hint_y=.3)
self.list_view.container.padding = self.pad
self.list_view.container.spacing = self.space
mainlayout.add_widget(self.list_view)
return mainlayout
def list_item_args_converter(self,col,obj):
return {
'text': obj,
'size_hint_y': .3,
'text_size' : (self.root.width-2*self.pad-2*self.text_border , None),
'height': 32,
'halign': 'left',
'valign': 'middle',
'deselected_color':[.5,.5,.5,1],
'selected_color':[1.,1.,1.,1]
}
if __name__ == '__main__':
MyApp().run()