2013-06-05 54 views

回答

4

HM,像

ScrollView: 
    size_hint: None, None 
    size: 500, 320 
    pos_hint: {'center_x': .5, 'center_y': .5} 
    do_scroll_x: False 

    GridLayout: 
     cols: 1 
     padding: 10 
     spacing: 10 
     size_hint_y: None 
     height: self.minimum_height 

     ScrollButton: 
      text: '1' 
     ScrollButton: 
      text: '2' 
     ScrollButton: 
      text: '3' 
     ScrollButton: 
      text: '4' 
     ScrollButton: 
      text: '5' 
     ScrollButton: 
      text: '6' 

<[email protected]> 
    size_hint: None, None 
    size: 480, 40 

這裏,但我們真的沒有辦法動態創建的兒童(當然,會有辦法的,但他們是醜陋的),所以我把幾manualy,意思是你可以用kv創建ScrollView和GridLayout,然後把它們放到python裏面(使用ids,如doc中所述)。

編輯:更完整的使用應用和OBJECTPROPERTY

KV文件(scroll.kv)版本:

ScreenManager: 
    Screen: 
     ScrollView: 
      size_hint: None, None 
      size: 500, 320 
      pos_hint: {'center_x': .5, 'center_y': .5} 

      GridLayout: 
       cols: 1 
       padding: 10 
       spacing: 10 
       height: self.minimum_height 
       size_hint: None, None 
       do_scroll_x: False 
       id: container 

<ScrollButton> 
    size_hint: None, None 
    size: 480, 40 

Python文件(main.py):

from kivy.app import App 
from kivy.uix.button import Button 

class ScrollButton(Button): 
    pass 

class ScrollApp(App): 
    def build(self): 
     super(ScrollApp, self).build() 
     container = self.root.ids.container 
     for i in range(30): 
      container.add_widget(ScrollButton(text=str(i))) 
     return self.root # return root does not work 

if __name__ == '__main__': 
    ScrollApp().run() 
+0

有你看到問題。我的「ScrollViewApp」將是我的ScreenManager中的一個屏幕。我想使用ObjectProperty作爲參考動態地將按鈕附加到滾動條,但沒有骰子。真的沒有等效的方法嗎? –

+0

爲了給你一些背景,這是一個待辦事項列表應用程序。按鈕將是從存儲的表中調用的任務。 –

+0

被編輯顯示一個更完整的應用程序,應該讓你走上正軌。 – Tshirtman