android - 如何解决约束布局内与其他 subview 重叠的可扩展 ListView 滚动问题?

标签 android xml expandablelistview android-constraintlayout

我需要构建像主页这样的 Grofers,其中包含所有 View ,例如 viewpager、recyclerview、可扩展 ListView 和带有框架布局的线性布局,最重要的是向每个 View 添加滚动。但是可扩展 ListView 高度不是根据组元素获取的。它仅显示一个组 View 高度并在该特定高度内滚动所有 View 。 我尝试了 ScrollView 、嵌套 ScrollView 、线性布局,但都不适合该场景。

<androidx.constraintlayout.widget.ConstraintLayout
        android:orientation="vertical"
        android:id="@+id/ll_home"
        app:layout_constrainedHeight="true"
        app:layout_constrainedWidth="true"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <RelativeLayout
            android:id="@+id/linearLayout3"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_marginStart="8dp"
            android:layout_marginEnd="8dp"
            android:background="@color/colorOrange"
            app:layout_constrainedWidth="true"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@id/linearLayout3"
            app:layout_constraintBottom_toTopOf="@id/expandablelistview"
            app:layout_constraintHeight_default="wrap">
        </RelativeLayout>
        
        <ExpandableListView
            android:id="@+id/expandablelistview"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_alignParentTop="true"
            android:layout_marginTop="8dp"
            android:background="@color/colorBlue"
            android:groupIndicator="@null"
            android:layout_below="@id/linearLayout3" />

</androidx.constraintlayout.widget.ConstraintLayout>

最佳答案

<androidx.constraintlayout.widget.ConstraintLayout
        android:orientation="vertical"
        android:id="@+id/ll_home"
        app:layout_constrainedHeight="true"
        app:layout_constrainedWidth="true"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <RelativeLayout
            android:id="@+id/linearLayout3"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_marginStart="8dp"
            android:layout_marginEnd="8dp"
            android:background="@color/colorOrange"
            app:layout_constrainedWidth="true"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@id/linearLayout3"
            app:layout_constraintBottom_toTopOf="@id/expandablelistview"
            app:layout_constraintHeight_default="wrap">
        </RelativeLayout>

        <ExpandableListView
            android:id="@+id/expandablelistview"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            app:layout_constraintTop_toBottomOf="@+id/linearLayout3"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            android:layout_alignParentTop="true"
            android:layout_marginTop="8dp"
            android:background="@color/colorBlue"
            android:groupIndicator="@null"
            android:layout_below="@id/linearLayout3" />

</androidx.constraintlayout.widget.ConstraintLayout>

关于android - 如何解决约束布局内与其他 subview 重叠的可扩展 ListView 滚动问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58481060/

相关文章:

android - 从 Kotlin 隐藏静态 Java 方法

android - 带有 ExpandableListView 的 BaseExpandableListAdapter 返回错误的 subview

android - 使用现有证书为 React Native Android 应用程序生成签名的 apk

android - setAndAllowWhileIdle() 和 setExactAndAllowWhileIdle() 都不是每 15 分钟每个应用程序一次。每分钟闹钟怎么办

xml - 使用 xsl :for-each over an xml to decide which label-value pairs are displayed?

mysql - 加载 XML INFILE 和子列

android - OnChildClickListener 在可扩展 ListView 中不起作用

android - 如何使用两个 fragment 实现视频和视频列表

android - 让用户设置浅色或深色主题加上强调色

java - 无法使用 Apache POI 3.13 解析 CTDataModel