我需要构建像主页这样的 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/