下面是我的XML代码,我有多个可扩展的列表视图(5),每个视图都有不同的适配器,所有的视图都在垂直滚动视图中。但当点击每个可展开项目的标题时,它会显示项目,但不会展开(它会显示标题中的所有项目第一个设置高度)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".screens.home.ui.dailyreportes.DailyReportsDetailsFragment">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/linearLayoutCompat3"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ExpandableListView
android:id="@+id/elv_work_logs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
android:layout_weight="1"
android:divider="@android:color/darker_gray"
android:dividerHeight="0.5dp"
>
</ExpandableListView>
<ExpandableListView
android:id="@+id/elv_equipment_logs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/elv_work_logs"
app:layout_constraintVertical_bias="0.0"
android:layout_weight="1"
android:divider="@android:color/darker_gray"
android:dividerHeight="0.5dp"
>
</ExpandableListView>
<ExpandableListView
android:id="@+id/elv_material_delivery_logs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/elv_equipment_logs"
app:layout_constraintVertical_bias="0.0"
android:layout_weight="1"
android:divider="@android:color/darker_gray"
android:dividerHeight="0.5dp"
>
</ExpandableListView>
<ExpandableListView
android:id="@+id/elv_activity_logs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/elv_material_delivery_logs"
app:layout_constraintVertical_bias="0.0"
android:layout_weight="1"
android:divider="@android:color/darker_gray"
android:dividerHeight="0.5dp"
>
</ExpandableListView>
<ExpandableListView
android:id="@+id/elv_schedule_delays_logs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/elv_activity_logs"
app:layout_constraintVertical_bias="0.0"
android:layout_weight="1"
android:divider="@android:color/darker_gray"
android:dividerHeight="0.5dp"
>
</ExpandableListView>
</androidx.constraintlayout.widget.ConstraintLayout>
对于每个子布局,我尝试了match_parent和wrap_content,但得到了相同的结果。
1条答案
按热度按时间piv4azn71#
注意:我们不能在XML中为ExpandableListView的android:layout_height属性使用wrap_content值,除非严格指定了父级的大小
而且你也不需要scrollView,因为ExpandableListView在默认情况下是可滚动的。
您可以参考here