如何在 ExpandableListView 上的组项目之间而不是组和 child 之间有差距?

How to have a gap between group items but not between group and child on ExpandableListView?

我和How to remove specific space between parent and child in an ExpandableListView几乎有同样的问题。

我有一个 ExpandableListView,我想在展开时将我的组与第一个 child 组分开。

我尝试移除分隔线,但它使我的组项目靠在一起,根本没有 space。

我也尝试在组上使用底边距,在 child 上使用负边距,但是 child 与 parent 组分开了。

这是我的代码:

<ExpandableListView android:id="@android:id/list" android:layout_width="match_parent"
    android:layout_height="match_parent" android:groupIndicator="@null"
    android:layout_gravity="center_horizontal|top"
    android:divider="@android:color/transparent"
    android:dividerHeight="8dp"
    android:childDivider="#00000000"
    android:layout_marginTop="10dp"/>

就像我的组之间有一个很好的差距,但是当我展开它们时,第一个 child 与 parent 分开相同的 8dp 高度。

到目前为止,我找到的最佳解决方案是将 dividerHeight 设置为“0dp”,并将 paddingTop 添加到 xml 中的 groupItem。这样做你没有 Group 和它的孩子之间的分隔符,但你会在组之间有它。也许它不是历史上最好的解决方案,但是,您知道,ExpandableListView 不是历史上设计最好的视图...

内码:

您有 ExpandableListView 的地方:

<ExpandableListView
    [...]
    android:divider="@android:color/transparent"
    android:dividerHeight="0dp"/>

parent 视图中有组项目 xml 的位置:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="10dp">

在此示例中,我在组之间放置了 10dp 的 "divider",但在组与它之间没有放置 children。