KG6ZVP KG6ZVP - 1 month ago 14
Android Question

Set width to match constraints in ConstraintLayout

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.

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?

Loving this new layout system for my favorite platform!

Answer

match_parent is supported, but it is not as powerful as 0dp. With 0dp, you can think of your constraints as 'scalable' rather than 'filling whats left'.

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)

Comments