Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Hide child dividers in ExpandableListView

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?

like image 462
Alexander Oleynikov Avatar asked Jul 14 '10 10:07

Alexander Oleynikov


People also ask

What is expandablelistview in Android?

In Android, ExpandableListView is a View that shows items in a vertically scrolling two level list. Different from the listview by allowing two level groups which can individually be expanded to show its children. Each group can be expanded or collapsed individually to show or hide its children items.

How to have divider between parent and children in expandablelistview?

If you want to have divider between parent element of the ExpandableListView (Header) and don't want to have divider between children and parent , which is obviously the most natural case, then you have to do following: In your parent xml file add one View at the bottom of the layout with divider height and divider color that you need. Example:

How to remove the child divider from a list view?

If you want to remove child divider only, One simple trick is You can create a drawable with same color as of your child item's background color. Then set it as child divider. ShapeDrawable sd1 = new ShapeDrawable(new RectShape()); sd1.getPaint().setColor(YOUR CHILD ITEM BACKGROUND COLOR); mExpListView.setChildDivider(sd1); Or using xml:

How do I add padding to an expandable list view?

paddingLeft: set the padding from the left side of the Progress bar. paddingTop: set the padding from the top side of the expandable list view. paddingBottom: set the padding from the bottom side of the expandable list view. Padding: set the padding from the all side’s of the expandable list view.


1 Answers

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().

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.

Waiting for more answers...

like image 92
user393472 Avatar answered Sep 30 '22 19:09

user393472