我使用相同的方法来过度压缩TextView:
ScrollView:
id: scrlv
size_hint: (1, 1)
effect_cls: ScrollEffect #avoid overscrolling
TextInput:
id: ro_log
size_hint: (1, None)
height: max(self.minimum_height, scrlv.height) #required to enable scrolling when list starts to grow
readonly: True
background_color: 0,0,0,0
foreground_color: 1,1,1,1
但是对于包含ScrollView的ListView,下面的kv规范没有效果:
ListView:
id: commandListView
effect_cls: ScrollEffect #no effect !
adapter: ListAdapter(data=[], cls=main.CommandListButton, args_converter=lambda row_index,rec: {'text':rec, 'on_press':root.commandSelected})
height: '0dp'
size_hint_y: None
答案 0 :(得分:1)
以下是基本ListView的规则:
<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
所以如果你想访问ListView的ScrollView,可以使用:
self.container.parent.effect_cls = ScrollEffect
答案 1 :(得分:1)
这是解决方案,正如SP SP在上面的评论中所给出的那样:
ListView:
id: commandListView
adapter: ListAdapter(data=[], cls=main.CommandListButton, args_converter=lambda row_index,rec: {'text':rec, 'on_press':root.historyItemSelected})
height: '0dp'
size_hint_y: None
on_parent: self.container.parent.effect_cls = ScrollEffect #prevents overscrolling
这当然需要
#: import ScrollEffect kivy.effects.scroll.ScrollEffect
在kv文件的顶部。