ScrollView 不滚动 GridLayout
ScrollView not scrolling GridLayout
我有一个 GridLayout,它需要一些 Card 小部件,这些小部件基本上是 RoundedRectangles 并且是应该填充特定信息,问题是 GridLayout 可以容纳很多卡片,我希望用户滚动小部件。直觉上,我在 ScrollView 中定义它来滚动 gridlayout,但是,scrollview 不起作用。我怀疑问题是网格布局的高度实际上并没有改变并且没有适应它的 children 但我该如何实现呢?
我的 Python 代码:
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.lang import Builder
Builder.load_file("design.kv")
class MyLayout(Widget):
pass
class MainApp(App):
def build(self):
return MyLayout()
if __name__ == "__main__":
MainApp().run()
我的 KV 代码:
#:kivy 2.0.0
<Card@Widget>:
size_hint_y: None
height: (self.parent.height - self.parent.padding[1] * 3) / 2
canvas:
Color:
rgba: 1, 1, 1, 1
RoundedRectangle:
size: self.size
pos: self.pos
radius: [5]
<MyLayout>:
ScrollView:
size: root.size
do_scroll_x: False
do_scroll_y: True
GridLayout:
id: song_menu
cols: 2
size_hint_y: None
height: self.parent.height
padding: 10
spacing: 10
canvas.before:
Color:
rgba: 1, 0, 0, 1
Rectangle:
size: self.size
pos: self.pos
Card:
Card:
Card:
Card:
Card:
Card:
编辑: 我忘了说我已经试过了 height: self.minimum_height
,但是,一件荒谬的事情发生了。 gridlayout 有一个奇怪的行为,并没有出现。基本上我在终端得到这个:
[CRITICAL] [Clock ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute
GridLayout
高度未调整,因为您用以下方法限制了它:
height: self.parent.height
尝试将其替换为:
height: self.minimum_height
我有一个 GridLayout,它需要一些 Card 小部件,这些小部件基本上是 RoundedRectangles 并且是应该填充特定信息,问题是 GridLayout 可以容纳很多卡片,我希望用户滚动小部件。直觉上,我在 ScrollView 中定义它来滚动 gridlayout,但是,scrollview 不起作用。我怀疑问题是网格布局的高度实际上并没有改变并且没有适应它的 children 但我该如何实现呢? 我的 Python 代码:
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.lang import Builder
Builder.load_file("design.kv")
class MyLayout(Widget):
pass
class MainApp(App):
def build(self):
return MyLayout()
if __name__ == "__main__":
MainApp().run()
我的 KV 代码:
#:kivy 2.0.0
<Card@Widget>:
size_hint_y: None
height: (self.parent.height - self.parent.padding[1] * 3) / 2
canvas:
Color:
rgba: 1, 1, 1, 1
RoundedRectangle:
size: self.size
pos: self.pos
radius: [5]
<MyLayout>:
ScrollView:
size: root.size
do_scroll_x: False
do_scroll_y: True
GridLayout:
id: song_menu
cols: 2
size_hint_y: None
height: self.parent.height
padding: 10
spacing: 10
canvas.before:
Color:
rgba: 1, 0, 0, 1
Rectangle:
size: self.size
pos: self.pos
Card:
Card:
Card:
Card:
Card:
Card:
编辑: 我忘了说我已经试过了 height: self.minimum_height
,但是,一件荒谬的事情发生了。 gridlayout 有一个奇怪的行为,并没有出现。基本上我在终端得到这个:
[CRITICAL] [Clock ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute
GridLayout
高度未调整,因为您用以下方法限制了它:
height: self.parent.height
尝试将其替换为:
height: self.minimum_height