2017-07-17 79 views
1

我已經在這幾個小時現在,嘗試每一種解決方案,我能找到這裏,並試圖隨機的東西.... 我試圖建立在由3個按鍵佈局頂部,然後是可滾動的GridLayout或BoxLayout。我只是無法弄清楚什麼是錯的......我讀過一個響應「綁定佈局的大小以適應自己:」但我使用的是screenmanagement,並且無法弄清楚如何使用我的代碼設置來做到這一點滾動網格佈局中的BoxLayout Kivy

<HomeScreen>: 
BoxLayout: 
    orientation: "vertical" 
    BoxLayout: 
     size_hint: 1,.1 
     orientation: "horizontal" 
     Button: 
      text:"1" 
     Button: 
      text:"2" 
     Button: 
      text:"3" 
    ScrollView: 
     GridLayout: 
      orientation: "vertical" 
      size_hint_y: None 
      row_default_height: 60 
      cols:1 

      Button: 
      Button: 
      Button: 
      Button: 
      Button: 
      Button: 
      Button: 
      Button: 
      Button: 
      Button: 
      Button: 
      Button: 
      Button: 
      Button: 
      Button: 
      Button: 

回答

0

你的代碼是正確的,你只需要指定GridLayout的高度。您可以使用height: self.minimum_height

重複的例子:

from kivy.app import App 
from kivy.uix.screenmanager import ScreenManager, Screen 
from kivy.lang import Builder 

kv_text = ''' 

<MyScreenManager>: 
    HomeScreen: 

<HomeScreen>: 
    BoxLayout: 
     orientation: "vertical" 
     BoxLayout: 
      size_hint: 1,.1 
      orientation: "horizontal" 
      Button: 
       text:"1" 
      Button: 
       text:"2" 
      Button: 
       text:"3" 
     ScrollView: 
      GridLayout: 
       orientation: "vertical" 
       size_hint_y: None 
       height: self.minimum_height #<<<<<<<<<<<<<<<<<<<< 
       row_default_height: 60 
       cols:1 

       Button: 
       Button: 
       Button: 
       Button: 
       Button: 
       Button: 
       Button: 
       Button: 
       Button: 
       Button: 
       Button: 
       Button: 
       Button: 
       Button: 
       Button: 
       Button: 
''' 

class MyScreenManager(ScreenManager): 
    pass 

class HomeScreen(Screen): 
    pass 

class MyApp(App): 
    def build(self): 
     return HomeScreen() 

def main(): 
    Builder.load_string(kv_text) 
    app = MyApp() 
    app.run() 

if __name__ == '__main__': 
    main() 

輸出:

enter image description here

+0

我發誓,我試過了...什麼接近......我想......哈哈謝謝你這麼多!現在,將「Grid:height:self.minimum_height」設置爲所需按鈕所需的最小高度的那條線是正確的? – Lemiwinks

+0

是的,沒錯。 'self.minimum_height'是包含所有子部件的最小高度。 @Lemiwinks – FJSevilla