我有这个代码。如果我将 Accordion 项目的数量增加到超过一定数量,应用程序就会失控。gridLayout 版本(已注释掉)按预期工作。违规区域位于 HERE 和 THERE 之间。
from kivy.app import App
from kivy.uix.spinner import Spinner, SpinnerOption
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.accordion import Accordion, AccordionItem
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.scrollview import ScrollView
from kivy.uix.gridlayout import GridLayout
from kivy.core.window import Window
class MusicController(App):
def build(self):
b = BoxLayout(orientation='vertical')
top = Spinner(text = '12', values = ["Songs","Artist","Playlist","Search"], background_color = (.3,.2,.5,1), size_hint_y = 0.1)
#< HERE >#
items = Accordion(orientation='vertical')
for x in xrange(30):
item = AccordionItem(title='Title %d' % x)
buttons = BoxLayout()
buttons.add_widget(Button(text='Play'))
buttons.add_widget(Button(text='Pause'))
buttons.add_widget(Button(text='Pause'))
item.add_widget(buttons)
items.add_widget(item)
#~ items = GridLayout(cols=1, spacing=10, size_hint_y=None)
#~ items.bind(minimum_height=items.setter('height'))
#~ for i in range(30):
#~ btn = Button(text=str(i),
#< THERE >#
sv = ScrollView(do_scroll_x = False)
sv.add_widget(items)
now_playing = BoxLayout(size_hint_y = 0.1)
for widget in ["Prev","Play","Pause","Next","NP"]:
now_playing.add_widget(Button(text=widget))
b.add_widget(top)
b.add_widget(sv)
b.add_widget(now_playing)
return b
if __name__ == '__main__':
MusicController().run()