You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Important: MATCH_PARENT is not recommended for widgets contained in a ConstraintLayout. Similar behavior can be defined by using MATCH_CONSTRAINT with the corresponding left/right or top/bottom constraints being set to "parent".
MATCH_PARENT is there because the underlying definition of layout_width/height has it.
MATCH_PARENTs behavior can be confusing because how it should behave in many situations is not obvious and has no clearly correct answer.
I would say if you are only using the most straight forward definition of "fill the parent in that axis" then it is clear what you mean by match_parent.
if you are adding constraints and margins on that axis use 0dp and Constrain it.
If we recommended it we would have a long section of the developer guide explaining its behavior and we would still have a many confused people.
@jafu888 Thank you for the explanations. In fact, I created this issue just to see these explanations. Can we put these explanation in the developer guide?
In the developer guide: https://developer.android.com/reference/androidx/constraintlayout/widget/ConstraintLayout, there is a note:
It suggests that
match_parent
is not recommended insideConstraintLayout
, and it also suggests an alternative. However, it didn't explain why it is not recommended. The lack of explanation causes some questions like https://stackoverflow.com/questions/59237466/how-come-youre-not-suppose-to-use-match-parent-in-constraint-layout and google-developer-training/android-basics-kotlin-tip-calculator-app-solution#34.It would be better to explain why
match_parent
is not recommended insideConstraintLayout
. Thanks.The text was updated successfully, but these errors were encountered: