Skip to content Skip to sidebar Skip to footer

Nested Constraint Layout Not Showing If Using Match_constraints

I'm trying to create a nested ConstraintLayout in Android. The objective is to have an Image to the left, and another constraint layout to the right, inside a constraint layout, as

Solution 1:

The situation faced was that OP was trying to add the created ConstraintLayout to another ConstraintLayout programatically. That was being made using

inflater.inflate(R.layout.box, null)

It was an incorrect approach, as this ignores the layout parameters from the box. What was made to fix it was

inflater.inflate(R.layout.box, PARENT_LAYOUT/* One that box was being added to*/)

This fixes some issues due to the fact that the layout parameters were now being respected by the parent layout.

More information: Understaing Android's Layout Inflater.inflate()

Solution 2:

For child views of each inner ConstraintLayout, use the id of parent layout instead of "parent". For example instead of:

app:layout_constraintTop_toTopOf="parent"

Use

app:layout_constraintTop_toTopOf="@+id/parent_id"

Post a Comment for "Nested Constraint Layout Not Showing If Using Match_constraints"