可扩展列表视图 - space 介于子视图和组视图之间

Expandable List View - space between child and group views

我正在开发一个简单的待办事项列表应用程序。我使用 ExpandableListView 来显示任务。出于某种原因,我总是在组视图和子视图之间出现奇怪的 space。我尝试在 xml 中将分隔线高度设置为 0dp,但它不会改变任何东西。

screenshot of the space

我的 xml 代码 ExpandableListView:

<ExpandableListView android:id="@+id/myList"
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content"
          android:layout_below="@+id/addTask"/>

编辑:

子视图xml:

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="130dp"
                android:background="#ff0000">



 <TextView android:layout_width="wrap_content" 
              android:layout_height="wrap_content"
              android:id="@+id/displayDetails"
              android:text="@string/detailsChild"
              android:textColor="#ffffff"/>

父视图xml:

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:background="#424242"
              android:layout_height="130dp"
                android:id="@+id/layoutCustom">

<View android:layout_width="fill_parent" android:layout_height="30dp"
      android:background="#FFFFFF"
      android:id="@+id/SpaceView"
      />


 <TextView
                android:layout_below="@id/SpaceView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="#FFFFFF"
                android:textSize="16sp"
                android:text="@string/nameofcourse"
                android:id="@+id/course" android:layout_margin="10dp"/>


  <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/date"
            android:id="@+id/date"
            android:textColor="#FFFFFF"
            android:textSize="16sp"
            android:layout_below="@+id/course"
            android:layout_marginLeft="10dp"/>


<TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/date"
            android:textColor="#FFFFFF"
            android:textSize="16sp"
            android:text="@string/typeoftask"
            android:layout_marginLeft="10dp"
            android:id="@+id/type" android:layout_marginTop="10dp"/>

<Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/delete"
            android:textSize="26sp"
            android:textColor="#FE2E2E"
            android:id="@+id/delete"
            android:minWidth="20dp"
            android:minHeight="0dp"
            android:focusable="false"
            android:layout_below="@+id/SpaceView"     android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"/>

<ImageButton android:layout_width="40dp" android:layout_height="50dp"
             android:id="@+id/mainEdit"
             android:src="@drawable/edit2"
             android:focusable="false"
             android:layout_below="@+id/date"
             android:layout_alignParentRight="true"/>



</RelativeLayout>

谢谢大家,祝大家度过愉快的一周!

我不明白这到底是什么原因,当我尝试你的 layout 文件时,它确实显示了 divider,即使 dividerHeight 设置为 0dp,但是将一些自定义颜色设置为 android:divider 并将 dividerHeight 设置为 0dp 确实删除了 white space。我在这里粘贴xml,你可以自己检查一下,看看是否有帮助,

<ExpandableListView android:id="@+id/myList"
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"
      android:divider="#000" <!-- Use any color or drawable -->
      android:dividerHeight="0dp"
      android:layout_below="@+id/addTask"/>