0

Following snippet from my layout xml:

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintTop_toBottomOf="@id/fragment_home_info_card_car_position"
            android:maxHeight="300dp"
            >

                <androidx.core.widget.NestedScrollView        
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:elevation="10dp">

                    <include
                        android:id="@+id/fragment_home_filter_chips"
                        layout="@layout/selection_chips"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_margin="4dp" />

                </androidx.core.widget.NestedScrollView>


        </androidx.constraintlayout.widget.ConstraintLayout>

wraps the content correctly, it wraps the include and doesn't exceed the height. But the content of the include get cut off approx 100dp down when scrolling. This may be because there is a rather slow fill of the include (in the background with a lifeCyclescope coroutine).

In my effort to overcome this I just constraint the height to a fixed value like this:

<androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="300dp"
            app:layout_constraintTop_toBottomOf="@id/fragment_home_info_card_car_position"
            
            >
...

Now suddenly the height of the include was correctly justified, and I could scroll down the bottom of it, but of course not constrained to the content if it was smaller than 300dp...

My question is, how do I constraint the height as in the first snippet and is sure that my include is fully expanded (viewed expanded inside the scrollview) ?

Do maxHeight do some "magic" that isn't quite well here ?

Roar Grønmo
  • 2,926
  • 2
  • 24
  • 37
  • This is probably not the issue that you are having, but replace `match_parent` with `0dp` and the appropriate constraints. From the documentation: _"Important: MATCH_PARENT is not recommended for widgets contained in a ConstraintLayout. Similar behavior can be defined by using MATCH_CONSTRAINT with the corresponding left/right or top/bottom constraints being set to "parent"."_ – Cheticamp Jun 10 '21 at 14:40
  • Wonder why lint doesn't flag that actually... ...of course... but it is quite convenient just to say "match_parent". – Roar Grønmo Jun 10 '21 at 17:15
  • Should be a lint check but, alas, there is not. An earlier version of the text I quoted said that "unpredictable" things may happen if `match_parent` is used. That text has been removed, so it is possible that `match_parent` works OK but it is not guaranteed. – Cheticamp Jun 10 '21 at 17:19
  • I tried as you said to change to ` ` But this time it disappeared... – Roar Grønmo Jun 10 '21 at 18:20
  • I'll see if I manage to share a "proof-of-concept" on this... I'll do a "static" workaround until solved. – Roar Grønmo Jun 10 '21 at 18:23

0 Answers0