方向是硬编码的。如果您查看https://github.com/kivy/kivy/blob/master/kivy/uix/listview.py,您会发现:
Builder.load_string('''
<ListView>:
container: container
ScrollView:
pos: root.pos
on_scroll_y: root._scroll(args[1])
do_scroll_x: False
GridLayout:
cols: 1
id: container
size_hint_y: None
''')
我将此文件复制到项目目录中并将其替换为:
Builder.load_string('''
<ListView>:
container: container
ScrollView:
pos: root.pos
on_scroll_y: root._scroll(args[1])
do_scroll_x: False
GridLayout:
rows: 1
id: container
size_hint_y: None
''')
并使用此测试代码:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from listview import ListView
from kivy.uix.gridlayout import GridLayout
class MainView(GridLayout):
def __init__(self, **kwargs):
kwargs['cols'] = 2
super(MainView, self).__init__(**kwargs)
list_view = ListView(item_strings=[str(index) for index in range(100)])
self.add_widget(list_view)
if __name__ == '__main__':
from kivy.base import runTouchApp
runTouchApp(MainView(width=800))
我设法得到水平列表。然而,它打破了滚动。看起来您必须更多地更改此配置并修改滚动方法才能获得所需的结果。