为什么我的kv BoxLayout不能水平居中?
问题描述:
这是我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()
的想法是有登录字段出现垂直和水平居中两者。垂直方向按我所期望的方式工作,但字段和按钮全部显示在窗口左边缘而不是中间。
我在这里错过了一些非常基本的东西,或者只是完全错误地去了解它?
答
啊,愚蠢的迈克。我只是重新阅读了第100次的文档,它正面对着我。
pos_hint不被所有的布局使用!
来自FloatLayout文档:FloatLayout尊重其子级的pos_hint和size_hint属性。
更改了我的test.kv文件,使外层BoxLayout现在成为FloatLayout,并且所有内容都按预期工作。