我有一个ScrollView,下面有MDList,我希望“当我单击MDlist时,MDDropdownMenu项应恰好在该项上打开”。
ScrollView:
pos_hint: {'center_x': .5, 'center_y': .4}
MDList:
pos_hint: {'center_x': .5, 'center_y': .85}
id: box
答案 0 :(得分:1)
from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.list import OneLineListItem
from kivymd.uix.menu import MDDropdownMenu
KV = """
ScrollView:
MDList:
id: box
cols: 1
"""
class Test(MDApp):
def build(self):
return Builder.load_string(KV)
def show_menu(self, instance):
menu_items = [{"text": f"Item {i}"} for i in range(5)]
menu = MDDropdownMenu(caller=instance, items=menu_items, width_mult=4
)
menu.open()
def on_start(self):
for i in range(20):
self.root.ids.box.add_widget(
OneLineListItem(text=f"Item {i}", on_release=self.show_menu)
)
Test().run()