0

以下来自我的布局 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>

正确包装内容,它包装include并且不超过高度。但是include滚动时,内容会被截断大约 100dp。这可能是因为包含的填充相当慢(在后台使用lifeCyclescope协程)。

为了克服这个问题,我只是将高度限制为固定值,如下所示:

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

现在突然间包含的高度是正确的,我可以向下滚动它的底部,但如果它小于 300dp,当然不限于内容......

我的问题是,我如何限制第一个片段中的高度,并确保我的包含完全展开(在滚动视图中查看展开)?

maxHeight一些在这里不太好的“魔法”吗?

4

0 回答 0