我在Kivy应用中有一个scrollview对象。滚动视图包含一个框式布局,其中包含一定数量的图像。在运行时,更多图像将添加到此BoxLayout中。目前,我尝试通过更改scroll_y属性来将scrollview调整为所做的更改,并且效果很好。在某个时候它卡住了(在第225张图片上),我不知道如何解决这个问题。如果更改了Kivy,是否可以自动重新调整滚动视图?还是有比我更好的方法来解决这个问题?
这是我到目前为止在python中所做的(在scrollview类内部:]]
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
我在Kivy应用中有一个scrollview对象。滚动视图包含一个框式布局,其中包含一定数量的图像。在运行时,更多图像将添加到此BoxLayout中。此刻我尝试...
当我回答了您关于该主题的原始问题时,我使用了测试: