如何从ExpandableListView的子代中删除分隔符?

问题描述 投票:1回答:1

我在android中制作多选题。为此,我使用Expandable listview。我不想在子视图之间以及子视图和父视图之间显示空格(分隔符)。但我想在不同的可扩展列表视图之间分配。我搜索了很多,但我发现的是在子视图之间添加透明色,但它仍然显示子视图之间的空间。那么有什么办法可以删除子视图之间的空间。这是我的Expandable listview的xml代码。

<ExpandableListView
 android:id="@+id/list_single_choice_questions"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:dividerHeight="5dp"
 android:layout_marginLeft="8dp"
 android:layout_marginRight="8dp"
 android:divider="#ffffff"
 android:childDivider="#00000000"/>
android expandablelistview divider
1个回答
0
投票

android:divider选择父绘图或android:footerDividersEnabled / android:headerDividersEnabled可能是你正在寻找父视图。这些都是从ListView父级继承的。

至于子视图,我们可以查看Java方法以编程方式设置它,请参阅Android docs on Expandable List。例如setChildDivider():

设置将在列表中的每个子项旁边绘制的drawable。这将使用与普通分隔符(setDivider(Drawable))相同的高度绘制,或者如果它没有固有高度,则由setDividerHeight(int)设置高度。

因此,使用的高度由setDividerHeight()或固有高度设定。

除此之外,您可以更改子视图的xml布局,以使每个视图之间的空间更小。

<LinearLayout
     android:id="@+id/child_list_item"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     <!--no padding or margin-->/>

编辑:

你可以尝试像这样创建一个childDividerShape drawable:

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <size android:height="0dp"/>
</shape>

然后将其设置为android:childDivider属性。

...
android:childDivider="@drawable/childDividerShape"
...
© www.soinside.com 2019 - 2024. All rights reserved.