2
我有這段代碼。如果我增加了一定數量的手風琴項目,該應用程序就會失靈。 gridLayout版本(註釋掉)按預期工作。犯罪區域位於HERE和THERE之間。Kivy ScrollView +手風琴錯誤
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()
這工作,我很欣賞它。但爲什麼另一個容器不需要這個,有沒有辦法讓它更具動態性?我的意思不是要忘恩負義,我很欣賞這一點。 – 2013-03-27 04:23:40
更新了包含解釋的答案,基本上你將GridLayout的高度綁定到minimum_height。 – 2013-03-27 13:45:20