Android:在 ExpandableListView 中隐藏子分隔符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3245234/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android: Hide child dividers in ExpandableListView
提问by Alexander Oleynikov
I need to completely remove dividers from ExpandableListView. As for parent items it's a setDividerHeight method where I can pass a zero value. But there's no similar method for child divider. Is there any way to hide it?
我需要从 ExpandableListView 中完全删除分隔线。至于父项,它是一个 setDividerHeight 方法,我可以在其中传递零值。但是对于子分隔符没有类似的方法。有什么办法可以隐藏吗?
回答by user393472
If you want to completely remove dividers from ExpandableListView
, setDividerHeight
is ok for both parent and child items. Child divider will be draw using the same height as the normal divider or set by setDividerHeight()
.
如果您想从 中完全删除分隔线ExpandableListView
,setDividerHeight
对于父项和子项都可以。子分隔线将使用与普通分隔线相同的高度绘制或由 设置setDividerHeight()
。
And I am using one work around for us to hide one and unhide the other one, just set the divider and items in the same color like below:
我正在使用一种解决方法来隐藏一个并取消隐藏另一个,只需将分隔线和项目设置为相同的颜色,如下所示:
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
must below setChildDivider
and setDivider
, or the height will be 0.
setDividerHeight
必须低于setChildDivider
和setDivider
,否则高度将为 0。
Waiting for more answers...
等待更多答案...
回答by David-mu
to hide the child divider set it color to transparent #00000000
隐藏子分隔符将其颜色设置为透明 #00000000
define transparent in your color.xml file
在 color.xml 文件中定义透明
<color name="transparent">#00000000</color>
and then set the child divider
然后设置子分隔符
listView.setChildDivider(getResources().getDrawable(R.color.transparent))
or in the layout xml file
或在布局xml文件中
<ExpandableListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:childDivider="#00000000"/>
回答by Ishan Khanduja
You can use attribute
您可以使用属性
<ExpandableListView
android:id="@+id/interestlvExp"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:divider="@null">
</ExpandableListView>
But this will remove group list divider as well.
但这也将删除组列表分隔符。
回答by Mr.Moudgil
instead of writing lengthy code use property ExpandableListView
.
It will work :-
使用 property 代替编写冗长的代码ExpandableListView
。它会起作用:-
android:childDivider="@android:color/transparent"
回答by Amit
If you want to remove child divider only, You can create a drawable with same color as of child background color. Then set it as your child divider.
如果您只想删除子分隔符,您可以创建一个与子背景颜色相同颜色的可绘制对象。然后将其设置为您的子分隔符。
ShapeDrawable sd1 = new ShapeDrawable(new RectShape());
sd1.getPaint().setColor(YOUR CHILD ITEM BACKGROUND COLOR);
mExpListView.setChildDivider(sd1);
ShapeDrawable sd1 = new ShapeDrawable(new RectShape());
sd1.getPaint().setColor(YOUR CHILD ITEM BACKGROUND COLOR);
mExpListView.setChildDivider(sd1);
回答by Lilo
Set the divider height of your expandableListView to 0
将 expandableListView 的分隔线高度设置为 0
//setDividerHeight(0)
And then add a view at the bottom in your headerView xml
然后在 headerView xml 的底部添加一个视图
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_gravity="bottom"
android:background="@android:color/darker_gray"
/>