【发布时间】:2020-05-26 00:33:30
【问题描述】:
我的 Kivy 应用中有一个滚动视图对象。滚动视图包含一个 boxlayout,其中包含一定数量的图像。在运行时,更多的图像被添加到这个 boxlayout 中。目前,我尝试通过更改 scroll_y 属性来调整滚动视图以适应更改,并且效果很好。在某些时候它卡住了(大约在第 225 张图像上),我不知道如何解决这个问题。如果更改,Kivy 是否有办法自动重新调整滚动视图?还是有比我做的更好的方法来解决这个问题?
这就是我迄今为止在 python 中所做的事情(在滚动视图类中):
def on_scroll_y(self, instance, scroll_val):
global main_screen, generate_id
if scroll_val < get_scroll_distance() * scrolls_to_another_page:
box = main_screen.ids.notebook_image # this is the boxlayout that holds the images
new_image = MyImage() # just an image class
new_image.id = next(generate_id)
box.add_widget(new_image)
self.scroll_y = new_image.height / box.height # this is my try to adjust the scroll value
在kv文件中是这样定义的:
MyScrollView:
bar_color: [1, 0, 0, 1]
id: notebook_scroll
padding: 0
spacing: 0
do_scroll: (False, True) # up and down
BoxLayout:
padding: 0
spacing: 0
orientation: 'vertical'
id: notebook_image
size_hint: 1, None
height: self.minimum_height
MyImage:
<MyImage>:
source: 'images/notebook2.png'
allow_stretch: True
keep_ratio: False
size: root.get_size_for_notebook() #not important for this case, just screen size manipulation
size_hint: None, None
【问题讨论】:
标签: python kivy kivy-language