微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在具有最大高度的约束布局内包含嵌套滚动视图导致包含可变高度不能在其全高度展开

如何解决在具有最大高度的约束布局内包含嵌套滚动视图导致包含可变高度不能在其全高度展开

以下来自我的布局 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 是否做了一些在这里不太好的“魔法”?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。