2016-09-22 59 views
0

Iam嘗試將floatlayout對齊中心,幫助我? 上傳的圖像瞭解... 我的想法是在Kivy中添加圖標窗口8復古按鈕後重新創建佈局Windows 8復古。我無法在基維中心對齊FloatLayout

enter image description here

我的KV文件:

<SMAgro>: 
    AnchorLayout: 
     anchor_x: 'center' 
     anchor_y: 'center' 
     FloatLayout: 
      canvas: 
       Color: 
        rgb: [1,1,1,1] 
       Rectangle: 
        pos: self.pos 
        size: self.size 
      Button: 
       background_color: [.4,1,.1,1] 
       pos_hint: {'x': 0.26, 'y': 0.328571} 
       size_hint: 0.45, 0.3 
       text: "Equipamentos" 
#    StackLayout: 
#     pos: self.parent.pos 
#     size: self.parent.size 
#     orientation: 'lr-tb' 
#     Image: 
#      source: 'kivy.png' 
#      size_hint_x: None 
#      width: 74 
#     Label: 
#      size_hint_x: None 
#      width: 100 
#      text: "Equipamentos" 

      Button: 
       background_color: [.4,1,.1,1] 
       pos_hint: {'x': 0.26, 'y': 0.15} 
       size_hint: 0.225, 0.18 
       text: 'Configuracoes' 
      Button: 
       background_color: [.4,1,.1,1] 
       pos_hint: {'x': 0.486, 'y': 0.15} 
       size_hint: 0.225, 0.18 
       text: 'Sobre' 

回答

0

您可以設置FloatLayout大小,並添加pos_hint: {'center_y': 0.5, 'center_x': 0.5},因此,例如:你最寬按鈕有size_hint_x = 0.45和按鈕有size_hint_y = 0.18 + 0.3。

容器的大小:現在size_hint: 0.45, 0.48

,如果按鈕具有size_hint: 1, 1,它的100%的寬度和父容器(FloatLayout)的高度,它是等於45%的寬度和窗口的48%的高度。

這段代碼顯示爲中心FloatLayout

FloatLayout: 
    pos_hint: {'center_y': 0.5, 'center_x': 0.5} 
    size_hint: 0.45, 0.48 
    canvas: 
     Color: 
      rgb: [1,1,1,1] 
     Rectangle: 
      pos: self.pos 
      size: self.size 
    Button: 
     background_color: [.4,1,.1,1] 
     pos_hint: {'x': 0, 'y': 0.375} 
     size_hint: 1, 0.625 
     text: "Equipamentos" 
    Button: 
     background_color: [.4,1,.1,1] 
     pos_hint: {'x': 0, 'y': 0} 
     size_hint: .5, 0.375 
     text: 'Configuracoes' 
    Button: 
     background_color: [.4,1,.1,1] 
     pos_hint: {'x': .5, 'y': 0} 
     size_hint: .5, 0.375 
     text: 'Sobre' 

centered FloatLayout

+0

工作的兄弟,IAM不理解......我想...... 謝謝! –

+0

對不起,不好說明,但我的英語不是很好。最主要的是,將一個事物(本例中爲FloatLayout)居中會比中心許多事情更容易(這裏是3個按鈕) –