Android add other layout in ConstraintLayout using include tag Android add other layout in ConstraintLayout using include tag xml xml

Android add other layout in ConstraintLayout using include tag


Android include tag does work with ConstraintLayout, but you need to declare how big is the layout you want to include with the following attributes.

<include     layout="@layout/content_main"     android:layout_width="100dp"     android:layout_height="250dp"     .../>

For included layout having dynamic height use wrap_content as a value in layout_height or layout_width attributes of include tag.

<include    android:id="@+id/input_include"    layout="@layout/task_input"    android:layout_width="match_parent"    android:layout_height="wrap_content"/>

After that, your constraints should work.


In the constrain layout define the height and width and your constraints as follows:

<include    app:layout_constraintTop_toBottomOf="@id/custom_members_toolbar_layout"    app:layout_constraintBottom_toTopOf="@id/file_xfer_bottom_nav_bar"    android:layout_height="0dp"    android:layout_width="match_parent"    layout="@layout/file_xfer_upload_layout"/>

This will auto resize the height based on your constraints.

Cheers!


Not sure if the ideal solution but what worked for me was to have the include tag hosted by its own constraint layout such as

<androidx.constraintlayout.widget.ConstraintLayout    android:id="@+id/todaysFightLayout"    android:layout_width="match_parent"    android:layout_height="wrap_content"    app:layout_constraintBottom_toTopOf="@+id/tvLatestUpdate"    app:layout_constraintStart_toStartOf="parent"><include    layout="@layout/todays_fight_layout" /></androidx.constraintlayout.widget.ConstraintLayout>

And then add constraints from this new constraint layout to the next item to be displayed, in my case a textview with id tvLatestUpdate.