【发布时间】:2021-12-08 16:42:50
【问题描述】:
我有一个使用 AsyncImage 对象填充的 ScrollView。但是,我的 ScrollView 似乎认为没有什么可以向下滚动,并将其视为过度滚动。我认为这是因为我在实例化后添加到它的子布局,但不知道如何修复它。
错误行为:https://i.imgur.com/OjcR2RY.mp4
现在,我已经考虑过完全禁用过度滚动行为,但我需要它才能正常工作以用于未来的功能。
main.py
import gc
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.image import AsyncImage
from kivy.uix.widget import Widget
class ProviderWindow(Widget):
def __init__(self, **kwargs):
super(ProviderWindow, self).__init__(**kwargs)
self.C_L = GridLayout(cols=3, spacing=0, size_hint=(1, None), pos=(0, 0))
def search(self):
# Clear any existing images inside the view when starting a fresh search
for child in App.get_running_app().root.ids.image_scroll_view.children:
del child
App.get_running_app().root.ids.image_scroll_view.clear_widgets()
gc.collect(generation=2)
# GridView properties
self.C_L.col_default_width = 500
self.C_L.row_default_height = 500
urls = self.gb.search() # Get a list of URLs to load into AsyncImages (can simply be a list of Strings)
# Adding All images to GridLayout
for entry in urls:
img = AsyncImage(source=entry, keep_ratio=True, allow_stretch=True)
img.size_hint = (1, 1)
self.C_L.add_widget(img)
# Adding GridLayout to ScrollView
self.ids.image_scroll_view.add_widget(self.C_L)
class SimpleApp(App):
pass
简单.kv
ProviderWindow:
<ProviderWindow>:
BoxLayout:
orientation: "vertical"
size_hint: None, None
size: (root.size[0], root.size[1])
BoxLayout:
orientation: "horizontal"
size_hint: 1, 0.1
Button:
id:search_button
text:"Search"
on_press: root.search()
size_hint: 0.3,None
TextInput
id:tags
size_hint: 0.4, None
Button:
id:search_button
text:"More"
size_hint: 0.3,None
Button:
id:settings_button
text:"Settings"
size_hint: 0.2, None
ScrollView:
id: image_scroll_view
do_scroll_x: False
do_scroll_y: True
【问题讨论】:
标签: python user-interface kivy