Kivy 滚动视图不滚动
Kivy Scroll View does not scroll
我是第一次使用 kivys 滚动视图小部件,但我不确定如何得到它 运行。
我想向上滚动并通过不同的标签完成。
我怎样才能做到这一点?
滚动视图小部件需要哪些属性?
我可以使用任何布局吗?
谢谢
目前无法使用的代码:
<YearLabel@ButtonBehavior+Label>:
<YearScreen>:
canvas.before:
Color:
rgba: 1,1,1,0.25
Rectangle:
pos: self.pos
size: self.size
canvas.after:
Color:
rgba : 0,0,0,1
Rectangle:
pos: 160,1560
size: 419,60
ScrollView:
scroll_timeout: 250
scroll_distance: 20
do_scroll_y: True
do_scroll_x: False
height: 100
GridLayout:
cols : 1
spacing: 10
padding: 10
height: 50
YearLabel:
id: year_label
font_name: "Fonts/sans-serif.ttf"
text : "2020"
color: 0,0,0,1
pos : 0,1200
font_size: "120sp"
YearLabel:
id: year_label
font_name: "Fonts/sans-serif.ttf"
text : "2021"
color: 0,0,0,1
pos: 0,900
font_size: "120sp"
YearLabel:
id: year_label
font_name: "Fonts/sans-serif.ttf"
text : "2022"
color: 0,0,0,1
pos: 0,600
font_size: "120sp"
YearLabel:
id: year_label
font_name: "Fonts/sans-serif.ttf"
text : "2023"
color: 0,0,0,1
pos: 0,300
font_size: "120sp"
YearLabel:
id: year_label
font_name: "Fonts/sans-serif.ttf"
text : "2024"
color: 0,0,0,1
pos: 0,0
font_size: "120sp"
YearLabel:
id: year_label
font_name: "Fonts/sans-serif.ttf"
text : "2025"
color: 0,0,0,1
pos: 0,-300
font_size: "120sp"
YearLabel:
id: year_label
font_name: "Fonts/sans-serif.ttf"
text : "2026"
color: 0,0,0,1
pos: 0,-600
font_size: "120sp"
YearLabel:
id: year_label
font_name: "Fonts/sans-serif.ttf"
text : "2027"
color: 0,0,0,1
pos: 0,-900
font_size: "120sp"
YearLabel:
id: year_label
font_name: "Fonts/sans-serif.ttf"
text : "2028"
color: 0,0,0,1
pos: 0,-1200
font_size: "120sp"
YearLabel:
id: year_label
font_name: "Fonts/sans-serif.ttf"
text : "2029"
color: 0,0,0,1
pos: 0,-1500
font_size: "120sp"
YearLabel:
id: year_label
font_name: "Fonts/sans-serif.ttf"
text : "2030"
color: 0,0,0,1
pos: 0,-1800
font_size: "120sp"
如果 ScrollView
的子项 (GridLayout
) 小于 ScrollView
,则 ScrollView
将不起作用。通常,GridLayout
足以容纳其所有子项(YearLabels
)。方便的是,GridLayout
可以计算出该大小。这是使用它的 kv
的修改版本:
ScrollView:
scroll_timeout: 250
scroll_distance: 20
do_scroll_y: True
do_scroll_x: False
GridLayout:
cols : 1
spacing: 10
padding: 10
size_hint_y: None # required since we are setting height
height: self.minimum_height # let GridLayout calculate height
此外,我从 ScrollView
中删除了 height: 100
,因为它没有效果。
为了让 GridLayout
计算 minimum_height
,它的所有子项都必须具有明确定义的 heights
。所以,我在你的 YearLabel
规则中添加了:
<YearLabel@ButtonBehavior+Label>:
size_hint: 1, None
height: dp(100)
我是第一次使用 kivys 滚动视图小部件,但我不确定如何得到它 运行。 我想向上滚动并通过不同的标签完成。
我怎样才能做到这一点?
滚动视图小部件需要哪些属性? 我可以使用任何布局吗?
谢谢
目前无法使用的代码:
<YearLabel@ButtonBehavior+Label>:
<YearScreen>:
canvas.before:
Color:
rgba: 1,1,1,0.25
Rectangle:
pos: self.pos
size: self.size
canvas.after:
Color:
rgba : 0,0,0,1
Rectangle:
pos: 160,1560
size: 419,60
ScrollView:
scroll_timeout: 250
scroll_distance: 20
do_scroll_y: True
do_scroll_x: False
height: 100
GridLayout:
cols : 1
spacing: 10
padding: 10
height: 50
YearLabel:
id: year_label
font_name: "Fonts/sans-serif.ttf"
text : "2020"
color: 0,0,0,1
pos : 0,1200
font_size: "120sp"
YearLabel:
id: year_label
font_name: "Fonts/sans-serif.ttf"
text : "2021"
color: 0,0,0,1
pos: 0,900
font_size: "120sp"
YearLabel:
id: year_label
font_name: "Fonts/sans-serif.ttf"
text : "2022"
color: 0,0,0,1
pos: 0,600
font_size: "120sp"
YearLabel:
id: year_label
font_name: "Fonts/sans-serif.ttf"
text : "2023"
color: 0,0,0,1
pos: 0,300
font_size: "120sp"
YearLabel:
id: year_label
font_name: "Fonts/sans-serif.ttf"
text : "2024"
color: 0,0,0,1
pos: 0,0
font_size: "120sp"
YearLabel:
id: year_label
font_name: "Fonts/sans-serif.ttf"
text : "2025"
color: 0,0,0,1
pos: 0,-300
font_size: "120sp"
YearLabel:
id: year_label
font_name: "Fonts/sans-serif.ttf"
text : "2026"
color: 0,0,0,1
pos: 0,-600
font_size: "120sp"
YearLabel:
id: year_label
font_name: "Fonts/sans-serif.ttf"
text : "2027"
color: 0,0,0,1
pos: 0,-900
font_size: "120sp"
YearLabel:
id: year_label
font_name: "Fonts/sans-serif.ttf"
text : "2028"
color: 0,0,0,1
pos: 0,-1200
font_size: "120sp"
YearLabel:
id: year_label
font_name: "Fonts/sans-serif.ttf"
text : "2029"
color: 0,0,0,1
pos: 0,-1500
font_size: "120sp"
YearLabel:
id: year_label
font_name: "Fonts/sans-serif.ttf"
text : "2030"
color: 0,0,0,1
pos: 0,-1800
font_size: "120sp"
如果 ScrollView
的子项 (GridLayout
) 小于 ScrollView
,则 ScrollView
将不起作用。通常,GridLayout
足以容纳其所有子项(YearLabels
)。方便的是,GridLayout
可以计算出该大小。这是使用它的 kv
的修改版本:
ScrollView:
scroll_timeout: 250
scroll_distance: 20
do_scroll_y: True
do_scroll_x: False
GridLayout:
cols : 1
spacing: 10
padding: 10
size_hint_y: None # required since we are setting height
height: self.minimum_height # let GridLayout calculate height
此外,我从 ScrollView
中删除了 height: 100
,因为它没有效果。
为了让 GridLayout
计算 minimum_height
,它的所有子项都必须具有明确定义的 heights
。所以,我在你的 YearLabel
规则中添加了:
<YearLabel@ButtonBehavior+Label>:
size_hint: 1, None
height: dp(100)