Search code examples
androidandroid-constraintlayout

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?


Solution

  • 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'.

    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)