【发布时间】:2018-04-11 19:59:13
【问题描述】:
我想在 kivy 的滚动视图网格布局顶部覆盖一个矩形、按钮和标签,以提供带有当前屏幕名称的横幅和导航弹出窗口的按钮。我制作了一个按钮网格布局列表,用于链接到拼图应用中未来的小游戏。
我要放在最上面的内容在screenmanager.kv里面,而gridlayout在gameslist.kv里面。
一切都显示在屏幕上。网格布局垂直滚动。但是,它会滚动 screenmanager.kv 的内容,而不是在其下方。我希望横幅保持可见,浮动在网格上,始终位于窗口顶部的同一位置,尽管用户在网格布局中滚动了哪里。
screenmanager.kv:
<GamesListScreen>:
canvas.before:
Color:
rgba: 1, 0.6, 0.6, 1
Rectangle:
size: self.width, (self.height * 0.15)
pos: 0, (self.height * 0.85)
Button:
color: 1, 1, 1, 0
size_hint: None, None
height: Window.height * 0.15
width: self.height
pos: 0, (root.top * 0.85)
on_release:
root.open_NavPopup()
print('pressed')
Image:
source: 'images/NavIcon.png'
keep_ratio: False
allow_stretch: True
y: self.parent.y
x: self.parent.x
size: self.parent.size
Label:
font_size: self.width * 0.1
color: 1,1,1,1
center_x: self.width / 2
y: self.height / 2.35
text: 'Games List'
gameslist.kv:
#:import ScrollEffect kivy.effects.scroll.ScrollEffect
#:import Button kivy.uix.button.Button
<RootWidget>
effect_cls: ScrollEffect
GridLayout:
do_scroll_x: False
height: self.minimum_height
size_hint: 1, None
size: Window.width, (Window.height * .85)
spacing: 5, 5
padding: [0,(Window.height * .17),0,0]
cols: 1
on_parent:
self.add_widget(Button(text = "Game 1", size_hint_y = None, height = Window.height * .1))
self.add_widget(Button(text = "Game 2", size_hint_y = None, height = Window.height * .1))
self.add_widget(Button(text = "Game 3", size_hint_y = None, height = Window.height * .1))
self.add_widget(Button(text = "Game 4", size_hint_y = None, height = Window.height * .1))
self.add_widget(Button(text = "Game 5", size_hint_y = None, height = Window.height * .1))
self.add_widget(Button(text = "Game 6", size_hint_y = None, height = Window.height * .1))
self.add_widget(Button(text = "Game 7", size_hint_y = None, height = Window.height * .1))
self.add_widget(Button(text = "Game 8", size_hint_y = None, height = Window.height * .1))
self.add_widget(Button(text = "Game 9", size_hint_y = None, height = Window.height * .1))
self.add_widget(Button(text = "Game 10", size_hint_y = None, height = Window.height * .1))
gameslist.py,以防万一:
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.label import Label
from kivy.uix.image import Image
from kivy.uix.scrollview import ScrollView
Builder.load_file('gameslist.kv')
class RootWidget(ScrollView):
pass
class runGamesList(App):
def build(self):
root = RootWidget()
return root
我尝试将 canvas.before 更改为 canvas.after 并将叠加层放在 gridlayout 内,以便它随之滚动。都没有奏效。有小费吗?还是我应该放弃并做一些在 x 轴上滚动的事情?
【问题讨论】:
标签: android python python-3.x kivy