【发布时间】:2019-08-08 16:51:21
【问题描述】:
我点击顶部固定菜单中的按钮,即使垂直滚动视图中有一个按钮,它也不会影响固定菜单。
我正在尝试单击顶部固定菜单中的按钮,但操作正在发送到下面的水平滚动视图。
我是 kivy 甚至编程的新手,我正在使用 Python 3.7 和 Kivy(1.11.1) 创建一个应用程序,这有点像 Netflix 的页面布局,其中有一个固定在顶部和底部的菜单它有一个垂直滚动视图,里面有一些水平滚动视图(就像 Netlix 的目录,例如:我的列表、继续观看、系列等)。问题是,当我向下滚动垂直 ScrollView 并且水平滚动视图之一位于顶部的固定菜单后面时,事件将发送到此水平滚动视图而不是滚动视图内容上方的固定菜单。如果我向下滚动垂直 Scrollview 并且其中一个水平滚动视图“落后”(在引号中,因为我想它们不应该相互碰撞)顶部的菜单,如果我单击菜单,则事件正在发生发送到水平滚动视图。
from kivy.app import App
from kivy.lang.builder import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.scrollview import ScrollView
Builder.load_string(
'''
<ScrollApp>:
orientation: 'vertical'
BoxLayout:
size_hint: 1, 0.12
Button:
text: 'Fixed Menu'
on_press: print('This button stops working if there is a horizontal scrollview "behind"')
ScrollView:
bar_width: 10
scroll_type: ['bars', 'content']
BoxLayout:
orientation: 'vertical'
size_hint: 1, None
height: self.minimum_height
padding: 22, 0, 22, 50
spacing: 50
canvas:
Color:
rgba: .15, .15, .15, .9
Rectangle:
size: self.size
pos: self.pos
Button:
size_hint: None, None
width: 100
height: 100
on_press: print('This button does not overlap the menu above')
# "ScrollViews containers"
Custom
Custom
Custom
Custom
Custom
BoxLayout:
size_hint: 1, 0.12
Button:
on_press: print("This menu at the bottom is not affected by the problem that occurs with the top one")
<Custom@BoxLayout>:
orientation: 'vertical'
size_hint: 1, None
height: self.minimum_height
Label:
size_hint: None, None
size: self.texture_size
id: label
font_size: 20
text: 'Teste'
ScrollView:
do_scroll: True, True
size_hint: 1, None
height: 150
GridLayout:
id: grid
size_hint: None, 1.01
width: self.minimum_width
spacing: 5
cols: 3
Button:
size_hint: None, None
size: 400, 150
on_press: print('ScrollView button pressed')
Button:
size_hint: None, None
size: 400, 150
on_press: print('ScrollView button pressed')
Button:
size_hint: None, None
size: 400, 150
on_press: print('ScrollView button pressed')
''' )
class ScrollApp(BoxLayout):
pass
class Test(App):
def build(self):
return ScrollApp()
Test().run()
【问题讨论】:
标签: python kivy scrollview kivy-language