android ExpandableListView在展开时不将UI推到其下

vwoqyblh  于 2023-06-20  发布在  Android
关注(0)|答案(1)|浏览(159)

下面是我的XML代码,我有多个可扩展的列表视图(5),每个视图都有不同的适配器,所有的视图都在垂直滚动视图中。但当点击每个可展开项目的标题时,它会显示项目,但不会展开(它会显示标题中的所有项目第一个设置高度)

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. xmlns:tools="http://schemas.android.com/tools"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent"
  7. android:orientation="vertical"
  8. tools:context=".screens.home.ui.dailyreportes.DailyReportsDetailsFragment">
  9. <ScrollView
  10. android:layout_width="match_parent"
  11. android:layout_height="match_parent"
  12. >
  13. <androidx.constraintlayout.widget.ConstraintLayout
  14. android:id="@+id/linearLayoutCompat3"
  15. android:layout_width="match_parent"
  16. android:layout_height="match_parent"
  17. app:layout_constraintBottom_toBottomOf="parent"
  18. app:layout_constraintEnd_toEndOf="parent"
  19. app:layout_constraintStart_toStartOf="parent"
  20. app:layout_constraintTop_toTopOf="parent">
  21. <ExpandableListView
  22. android:id="@+id/elv_work_logs"
  23. android:layout_width="match_parent"
  24. android:layout_height="wrap_content"
  25. app:layout_constraintBottom_toBottomOf="parent"
  26. app:layout_constraintEnd_toEndOf="parent"
  27. app:layout_constraintStart_toStartOf="parent"
  28. app:layout_constraintTop_toTopOf="parent"
  29. app:layout_constraintVertical_bias="0.0"
  30. android:layout_weight="1"
  31. android:divider="@android:color/darker_gray"
  32. android:dividerHeight="0.5dp"
  33. >
  34. </ExpandableListView>
  35. <ExpandableListView
  36. android:id="@+id/elv_equipment_logs"
  37. android:layout_width="match_parent"
  38. android:layout_height="wrap_content"
  39. app:layout_constraintBottom_toBottomOf="parent"
  40. app:layout_constraintEnd_toEndOf="parent"
  41. app:layout_constraintStart_toStartOf="parent"
  42. app:layout_constraintTop_toBottomOf="@+id/elv_work_logs"
  43. app:layout_constraintVertical_bias="0.0"
  44. android:layout_weight="1"
  45. android:divider="@android:color/darker_gray"
  46. android:dividerHeight="0.5dp"
  47. >
  48. </ExpandableListView>
  49. <ExpandableListView
  50. android:id="@+id/elv_material_delivery_logs"
  51. android:layout_width="match_parent"
  52. android:layout_height="wrap_content"
  53. app:layout_constraintBottom_toBottomOf="parent"
  54. app:layout_constraintEnd_toEndOf="parent"
  55. app:layout_constraintStart_toStartOf="parent"
  56. app:layout_constraintTop_toBottomOf="@+id/elv_equipment_logs"
  57. app:layout_constraintVertical_bias="0.0"
  58. android:layout_weight="1"
  59. android:divider="@android:color/darker_gray"
  60. android:dividerHeight="0.5dp"
  61. >
  62. </ExpandableListView>
  63. <ExpandableListView
  64. android:id="@+id/elv_activity_logs"
  65. android:layout_width="match_parent"
  66. android:layout_height="wrap_content"
  67. app:layout_constraintBottom_toBottomOf="parent"
  68. app:layout_constraintEnd_toEndOf="parent"
  69. app:layout_constraintStart_toStartOf="parent"
  70. app:layout_constraintTop_toBottomOf="@+id/elv_material_delivery_logs"
  71. app:layout_constraintVertical_bias="0.0"
  72. android:layout_weight="1"
  73. android:divider="@android:color/darker_gray"
  74. android:dividerHeight="0.5dp"
  75. >
  76. </ExpandableListView>
  77. <ExpandableListView
  78. android:id="@+id/elv_schedule_delays_logs"
  79. android:layout_width="match_parent"
  80. android:layout_height="wrap_content"
  81. app:layout_constraintBottom_toBottomOf="parent"
  82. app:layout_constraintEnd_toEndOf="parent"
  83. app:layout_constraintStart_toStartOf="parent"
  84. app:layout_constraintTop_toBottomOf="@+id/elv_activity_logs"
  85. app:layout_constraintVertical_bias="0.0"
  86. android:layout_weight="1"
  87. android:divider="@android:color/darker_gray"
  88. android:dividerHeight="0.5dp"
  89. >
  90. </ExpandableListView>
  91. </androidx.constraintlayout.widget.ConstraintLayout>

对于每个子布局,我尝试了match_parent和wrap_content,但得到了相同的结果。

piv4azn7

piv4azn71#

注意:我们不能在XML中为ExpandableListView的android:layout_height属性使用wrap_content值,除非严格指定了父级的大小
而且你也不需要scrollView,因为ExpandableListView在默认情况下是可滚动的。
您可以参考here

相关问题