【发布时间】:2011-03-15 18:51:41
【问题描述】:
我需要从 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"
你可以使用属性
<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(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"
/>
【讨论】:
android:divider="@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"/>
【讨论】: