问题描述
我有这段 QML 代码:
I have this piece of QML code:
Column {
spacing: units.gu(2)
anchors {
fill: parent
centerIn: parent
}
Row {
spacing: units.gu(4)
...
}
Row {
spacing: units.gu(4)
...
}
Row {
spacing: units.gu(4)
...
}
Row {
spacing: units.gu(4)
...
}
}
我试图将 Column 置于其父元素(页面元素)的中心,但它不起作用.如果尝试 centerIn: parent
在其中一个行中,它可以工作,但由于我有 4 行,它会破坏布局.但 Rows 对此做出回应,而不是我的 Column.
I'm trying to center Column in its parent element (a Page element), but it doesn't work.If a try to centerIn: parent
in one of the Rows, it works, but as I have 4 Rows, it break the layout. But Rows respond to this, instead my Column.
为什么让 centerIn: parent
适用于 Column?还有其他方法可以使这个居中吗?
Why make centerIn: parent
works for Column? Theres another ways to center this?
推荐答案
你不能设置'fill'和'centerIn',所以将列放在anchors.centerIn:parent中,将Rows放在anchors.horizontalCenter:parent.horizontalCenter中(不允许centerIn,因为它与父垂直定位冲突......).
you can't set 'fill' and 'centerIn',so put column in anchors.centerIn:parent and the Rows in anchors.horizontalCenter:parent.horizontalCenter (centerIn is not allowed cause it conflicts the parent vertical positionning....).
这篇关于为什么 anchors.centerIn 不适用于 Column 元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!