Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation: explain why match_parent is not recommended inside ConstraintLayout #231

Open
johnlinp opened this issue May 25, 2021 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@johnlinp
Copy link

In the developer guide: https://developer.android.com/reference/androidx/constraintlayout/widget/ConstraintLayout, there is a note:

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".

It suggests that match_parent is not recommended inside ConstraintLayout, 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 inside ConstraintLayout. Thanks.

@johnlinp johnlinp added the enhancement New feature or request label May 25, 2021
@jafu888
Copy link
Collaborator

jafu888 commented May 25, 2021

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.

@johnlinp
Copy link
Author

johnlinp commented Jun 8, 2021

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants