Android studio (v 2.3.1) keeps replacing the match_parent of a RelativeLayout with a fixed dp vanue. For example, when I type match_parent as the width, it repl
In short:
You cannot use match_parent as the dimension for children of ConstraintLayout. You should use 0dp which means "match_constraint" and constraint the sides to the parent's sides:
android:layout_width="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
or
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
With a bit of background (or - from where I believe the confusion stems):
Although I can't seem to find a proof, and my colleague claims I'm wrong - I'm certain the android documentation for constraintLayout used to direct us, the developers, to use "either 0dp or match_parent" as values for a layout_width or layout_height to indicate that the corresponding view's dimension should be determined by the constraintLayout using the specified constraints (rather than using a specified fixed value or by determining its content's dimension). I'm also pretty sure I used this value (match_parent) in this manner and it worked before switching to AndroidStudio 2.3.1.
Whether I'm right or delusional, the fact is that currently the documentation states:
Important: MATCH_PARENT is not supported for widgets contained in a ConstraintLayout, though similar behavior can be defined by using MATCH_CONSTRAINT with the corresponding left/right or top/bottom constraints being set to "parent".
Additionally, the 0dp value is regarded the same as I remember it used to:
The dimension of the widgets can be specified by setting the android:layout_width and android:layout_height attributes in 3 different ways:
(...)
- Using 0dp, which is the equivalent of "MATCH_CONSTRAINT"
The editor, using "infer constraints" as in the answer of Sirnivas actually uses the 0dp approach.
NOTE: "match_constraint" doesn't seem to be a value that can be used. 0dp is what seems to be the actual value for the dimension to match the constraints.