我需要完全从 ExpandableListView 中删除分隔符。对于父项,有一个 setDividerHeight 方法,可以传递零值来达到目的。但是没有类似的方法适用于子分隔符。是否有任何方法来隐藏它?
我需要完全从 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"/>
android:childDivider="@android:color/transparent"
作为另一种选择。 - cassioso<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"
ShapeDrawable sd1 = new ShapeDrawable(new RectShape());
sd1.getPaint().setColor(你的子项背景颜色);
mExpListView.setChildDivider(sd1);
//setDividerHeight(0)
然后在您的headerView xml中底部添加一个视图
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_gravity="bottom"
android:background="@android:color/darker_gray"
/>
android:divider="@color/tranceParent"
安卓:分隔线="@color/tranceParent"
<ExpandableListView
android:id="@+id/expandableList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/tranceParent"
app:layout_constraintTop_toTopOf="parent"
android:divider="@color/tranceParent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:listitem="@layout/item_parent_case"/>