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 trial

Android

Jovy Ong
seal-mask
.a{fill-rule:evenodd;}techdegree
Jovy Ong
Front End Web Development Techdegree Student 14,858 Points

Why 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

You're welcome :)

In 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