我需要从ExpandableListView中完全删除分隔符。至于父项,它是一个setDividerHeight方法,我可以传递零值。但是对于儿童分隔器没有类似的方法。有没有办法隐藏它?
如果你想从ExpandableListView
中完全删除分隔线,那么setDividerHeight
对父母和儿童物品都是好的。子分隔符将使用与普通分隔符相同的高度绘制或由setDividerHeight()
设置。
我正在使用一个工作来隐藏一个并取消隐藏另一个,只需将分隔符和项目设置为相同颜色,如下所示:
ExpandableListView expView = getExpandableListView();
expView.setGroupIndicator(null);
expView.setChildIndicator(null);
expView.setChildDivider(getResources().getDrawable(R.color.greywhite));
expView.setDivider(getResources().getDrawable(R.color.white));
expView.setDividerHeight(2);
setDividerHeight
必须低于setChildDivider
和setDivider
,否则高度将为0。
等待更多答案......
隐藏子分隔符将其颜色设置为透明#00000000
在color.xml文件中定义透明
<color name="transparent">#00000000</color>
然后设置子分隔符
listView.setChildDivider(getResources().getDrawable(R.color.transparent))
或者在布局xml文件中
<ExpandableListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:childDivider="#00000000"/>
您可以使用属性
<ExpandableListView
android:id="@+id/interestlvExp"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:divider="@null">
</ExpandableListView>
但这也将删除组列表分隔符。
而不是写冗长的代码使用属性ExpandableListView
。它会工作: -
android:childDivider="@android:color/transparent"
如果只想删除子分隔符,可以创建一个与子背景颜色相同颜色的drawable。然后将其设置为您的子分隔符。
ShapeDrawable sd1 = new ShapeDrawable(new RectShape());
sd1.getPaint().setColor(YOUR CHILD ITEM BACKGROUND COLOR);
mExpListView.setChildDivider(sd1);
将expandableListView的分隔符高度设置为0
//setDividerHeight(0)
然后在headerView xml的底部添加一个视图
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_gravity="bottom"
android:background="@android:color/darker_gray"
/>