Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJovy Ong
Front End Web Development Techdegree Student 14,858 PointsWhy use 0dp instead of match_constraint?
Going through the Android TD, I'm now at the ConstraintLayout lecture. My question is why did the instructor use 0dp as the layout_width instead of declaring it as match_constraint? Does it make a difference? Because it seems both do the job but match_constraint is better for readability IMO. Appreciate any help on this.
2 Answers
Jovy Ong
Front End Web Development Techdegree Student 14,858 PointsThanks for clearing that up. Indeed it writes 0dp in the xml file itself. I'll keep that in mind.
Lauren Moineau
9,483 PointsIn a ConstraintLayout, "0dp" means "match_constraint".
You will see that you cannot set layout_width or layout_height to "match_constraint" in your XML text file. You will get an error. It has to be set to "0dp". Similarly, in Android Studio's Layout Editor, when you set a view's layout_width or layout_height to "match_contstraint", it automatically displays "0dp".
Hope this helps
Lauren Moineau
9,483 PointsLauren Moineau
9,483 PointsYou're welcome :)