2014-11-01 99 views
5

目前,這是我的KV代碼不是滾動:如何在Kivy ScrollView中滾動GridLayout?

BoxLayout: 
    id: bl 
    orientation: 'vertical' 
    padding: 10, 10 
    row_default_height: '48dp' 
    row_force_default: True 
    spacing: 10, 10 

    GridLayout: 
     id: layout_content 
     cols: 1 
     row_default_height: '20dp' 
     row_force_default: True 
     spacing: 0, 0 
     padding: 0, 0 

     Label: 
      text: 'You don''t have any downloads. Please add new download from Home screen' 

你怎麼做上面的KV代碼滾動?我知道Kivy ScrollView只接受一個孩子,並且我已經讓GridLayout成爲新的ScrollView的子代。但它不起作用。任何建議?

回答

11

根據您禁用了滾動的孩子size_hint中的至少一個documentation for ScrollView

<Controller>: 
    layout_content: layout_content 
    BoxLayout: 
     id: bl 
     orientation: 'vertical' 
     padding: 10, 10 
     row_default_height: '48dp' 
     row_force_default: True 
     spacing: 10, 10 
     ScrollView: 
      size: self.size 
      GridLayout: 
       id: layout_content 
       size_hint_y: None 
       cols: 1 
       row_default_height: '20dp' 
       row_force_default: True 
       spacing: 0, 0 
       padding: 0, 0 

       Label: 
        text: "Lorem ipsum dolor sit amet" 

,並綁定佈局的尺寸使自己適應:

# main.py 

class Controller(FloatLayout): 
    layout_content=ObjectProperty(None) 

    def __init__(self, **kwargs): 
     super(Controller, self).__init__(**kwargs) 
     self.layout_content.bind(minimum_height=self.layout_content.setter('height')) 
+0

幾乎正是我只是做了! :)謝謝.. @syntax_error? :D – swdev 2014-11-01 22:14:31

+3

差不多:魔鬼在細節中,特別是用kv的東西:) – synw 2014-11-02 14:29:48

+0

不得不說,我有點希望Kivy-Designer很快成爲他們的主要意圖。它一定會幫助我們輕鬆設計界面。不幸的是,這個項目似乎處於休眠狀態。我錯過了PyQt這種方式.. – swdev 2014-11-02 15:45:55