Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested Constraint Layout ignores outer constraints

at the moment I'm trying to nest two Constraint Layouts in each other. For that I use the <include/> tag. What I see there is that the inner Constraint Layout ignores every constraints from the outer Constraint Layout. For making that more visible I draw a border around the inner Constraint Layout:

enter image description here

For trying that stuff I use the com.android.support.constraint:constraint-layout:1.0.0-alpha3.

My Question is now: did I do something wrong or is it even a bug from the alpha version?

like image 443
Joschka Schulz Avatar asked Mar 05 '26 19:03

Joschka Schulz


1 Answers

In order to add attributes to an included layout using the <include/> tag, you must specify BOTH width and height in the tag itself overriding or simply confirming those of the root tag of the included layout.

Example:

<include
    layout="@layout/item_place_custom"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintBottom_toBottomOf="parent" />

this results in the included layout being constrained to the bottom of its parent layout as expected.

This is not exclusive to the newer ConstraintLayout, this is the expected behavior of the <include/> tag as mentioned here

like image 117
Mahmoud AlyuDeen Avatar answered Mar 07 '26 13:03

Mahmoud AlyuDeen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!