Reputation: 2893
When I use android:layout_height="match_parent"
or android:layout_width="match_parent"
as height/width of children in Constraint Layout and build the Gradle file it automatically changes to android:layout_height="0dp"
or android:layout_widtht="0dp"
respectively.
Technically there is a huge difference between 0dp and match_parent.
Most of the time it doesn't effect my layout but sometimes this thing completely destroy my Constraint Layout.
I don't know why this happens.
Please guide me.
Upvotes: 3
Views: 8435
Reputation: 24988
The way worked with me for putting a Relative item, under another element, with width matching parent is:
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/xxx"
app:layout_constraintEnd_toEndOf="@+id/xxx"
>
Upvotes: 0
Reputation: 10126
You should not use match_parent for any view in a ConstraintLayout. Instead use "match constraints" (0dp)
match_parent
means filling whats left
where as 0dp means match constraints
. In ConstraintLayout, match_parent
is not supported.
match_parent
relies on it's parent for it's position (x,y & width/height) but 0dp can be defined by a constraint/position
Upvotes: 3
Reputation: 8449
match_parent isn't supported in ConstraintLayout. If you want the same behavior, use 0dp and set constraints on each side to the parent.
Upvotes: 7