设置宽度以匹配 ConstraintLayout 中的约束 [英] Set width to match constraints in ConstraintLayout
问题描述
我想将视图的左侧和右侧限制到其父视图的边距并使其填充分配的空间.但是,将宽度设置为 match_parent
或 wrap_content
似乎会产生相同的结果.
I would like to constrain a View's left and right sides to it's parent view's margins and make it fill the allotted space. However, setting width to either match_parent
or wrap_content
appears to produce the same result.
是否有与 match_constraints 等效的东西(相对于 match_parent 和 wrap_content)?match_parent
和 wrap_content
会影响布局还是在新的约束布局中被忽略?
Is there something equivalent to match_constraints (as opposed to match_parent and wrap_content)? Do match_parent
and wrap_content
affect the layout or are they ignored in the new constraint layout?
推荐答案
match_parent
不被支持,所以使用 android:layout_width=0dp"
.使用 0dp
,您可以将约束视为可扩展的"而不是填充剩下的".
match_parent
is not supported, so use android:layout_width="0dp"
. With 0dp
, you can think of your constraints as 'scalable' rather than 'filling whats left'.
此外,0dp
可以由位置定义,其中 match_parent
依赖于它的父级位置(x、y 和宽度、高度)
Also, 0dp
can be defined by a position, where match_parent
relies on it's parent for it's position (x,y and width, height)
这篇关于设置宽度以匹配 ConstraintLayout 中的约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!