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?
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.
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:
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:
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.
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With