2016-08-17 65 views
0

這是我test.kv文件:爲什麼我的kv BoxLayout不能水平居中?

BoxLayout: 
    BoxLayout: 
     orientation: 'vertical' 
     size_hint: None, None 
     height: '160sp' 
     width: '380sp' 
     pos_hint: {'center_x': .5, 'center_y': .5} 
     BoxLayout: 
      Label: 
       text: 'UserName' 
      TextInput: 
       id: user_name 
       text: '' 
     BoxLayout: 
      Label: 
       text: 'Password' 
      TextInput: 
       id: password 
       password: True 
       text: '' 
     BoxLayout: 
      Label: 
       text: 'Domain' 
      TextInput: 
       id: domain 
       text: 'howefarmingco.local' 
     Button: 
      text: 'Login' 
      size_hints: None, 1 
      width: .6 
      pos_hint: {'center_x': .5} 
      on_press: app.do_login() 

的想法是有登錄字段出現垂直和水平居中兩者。垂直方向按我所期望的方式工作,但字段和按鈕全部顯示在窗口左邊緣而不是中間。

我在這裏錯過了一些非常基本的東西,或者只是完全錯誤地去了解它?

回答

1

啊,愚蠢的邁克。我只是重新閱讀了第100次的文檔,它正面對着我。

pos_hint不被所有的佈局使用!

來自FloatLayout文檔:FloatLayout尊重其子級的pos_hint和size_hint屬性。

更改了我的test.kv文件,使外層BoxLayout現在成爲FloatLayout,並且所有內容都按預期工作。