【问题标题】:How to have a gap between group items but not between group and child on ExpandableListView?如何在 ExpandableListView 上的组项之间但组和子项之间没有间隙?
【发布时间】:2015-03-08 02:33:30
【问题描述】:

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

我有一个 ExpandableListView,我想将我的组分开,而当它展开时,组和第一个孩子之间没有间隙。

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

我还尝试在组上使用底部边距,在子级上使用负边距,但子级与父组分开。

这是我的代码:

<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"/>

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

【问题讨论】:

    标签: android expandablelistview


    【解决方案1】:

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

    内部代码:

    您拥有 ExpandableListView 的位置:

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

    您在父视图中拥有组项 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 的“分隔符”,而不是在一个组和它的孩子之间。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-15
      • 2020-06-22
      • 1970-01-01
      • 2020-10-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多