使用 python 和 kivy,我在 scrollView 中有一个可以垂直滚动的标签。滚动效果很好。内容是动态更新的。我想要以下行为:每次更新内容时,
我试过像下面的代码一样
self.ids['scroll_view'].scroll_y = 0
但它没有考虑任何约束。它总是滚动到文本的末尾。
在 .py 文件中:
class MyEngine(BoxLayout) :
display = StringProperty("")
def update_display(self) :
#some stuff
self.display = "some text" # this string can be long or short
# here (I suppose) I should measure something to scroll at the bottom iff the text is too long.
# The above line doesn't care about the text size, it always scrolls at the bottom :
self.ids['scroll_view'].scroll_y = 0
在 .kv 文件中:
<MyEngine>
BoxLayout:
orientation: 'vertical'
size : root.width, root.height
ScrollView:
id:scroll_view
size_hint: 1, 0.5
Label:
size_hint_y: None
text_size: self.width, None
height: self.texture_size[1]
font_size:'24sp'
halign: 'left'
text:root.display
GridLayout:
size_hint:1, 0.5
...etc....
感谢您的任何建议。