2016-09-07 98 views
0

我試圖用Kivy框架提供的KV lang創建接口。我想堆疊兩個BoxLayout小部件在彼此之上。當渲染第一個佈局時,它的默認高度爲350.否則我需要減少它。Kivy佈局不按預期呈現

下面是我的佈局

<RootWidget>: 
# this is the rule for your root widget, defining it's look and feel. 
StackLayout: 
    height: 350.0 
    BoxLayout: 
     id: 'letterBox' 
     height: 150.0 
     ActionButton: 
      width: 15.0 
      text: '-' 
     ActionButton: 
      width: 15.0 
      text: 'A' 
     ActionButton: 
      width: 15.0 
      text: 'B' 
     ActionButton: 
      width: 15.0 
      text: 'C' 
     ActionButton: 
      width: 15.0 
      text: 'D' 
     ActionButton: 
      width: 15.0 
      text: 'E' 
     ActionButton: 
      width: 15.0 
      text: 'F' 
     ActionButton: 
      width: 15.0 
      text: 'G' 
     ActionButton: 
      width: 15.0 
      text: 'H' 
     ActionButton: 
      width: 15.0 
      text: 'I' 
     ActionButton: 
      width: 15.0 
      text: 'J' 
     ActionButton: 
      width: 15.0 
      text: 'K' 
     ActionButton: 
      width: 15.0 
      text: 'L' 
     ActionButton: 
      width: 15.0 
      text: 'M' 
     ActionButton: 
      width: 15.0 
      text: 'N' 
     ActionButton: 
      width: 15.0 
      text: 'O' 
     ActionButton: 
      width: 15.0 
      text: 'P' 
     ActionButton: 
      width: 15.0 
      text: 'Q' 
     ActionButton: 
      width: 15.0 
      text: 'R' 
     ActionButton: 
      width: 15.0 
      text: 'S' 
     ActionButton: 
      width: 15.0 
      text: 'T' 
     ActionButton: 
      width: 15.0 
      text: 'U' 
     ActionButton: 
      width: 15.0 
      text: 'V' 
     ActionButton: 
      width: 15.0 
      text: 'W' 
     ActionButton: 
      width: 15.0 
      text: 'X' 
     ActionButton: 
      width: 15.0 
      text: 'Y' 
     ActionButton: 
      width: 15.0 
      text: 'Z' 
    BoxLayout: 
     id: 'contentBox' 
     height: 150.0 
     ActionButton: 
      text: '4' 

回答

1

你可以這樣做。嘗試使用size_hint,因爲它使您的應用程序響應,在所有屏幕分辨率中看起來都一樣。

BoxLayout: 
    orientation: 'vertical' 
     BoxLayout: 
      id: 'letterBox' 
      size_hint: 1, .15 

     BoxLayout: 
      id: 'contentBox' 
      size_hint: 1, .85 
+0

哇size_hint屬性改變了我的生活。我想知道如何相對大小的工作。 –