44

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?

Alexander Oleynikov
  • 19,190
  • 11
  • 37
  • 51

7 Answers7

54

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

Raymond
  • 2,276
  • 2
  • 20
  • 34
user393472
  • 556
  • 5
  • 2
  • Of course, if having the spacing for the padding were annoying, you could just set the DividerHeight to 0, and include a divider in the cell used in your custom adapter. To prevent the bottom item having a separator, you could just hide the separator if index == getGroupCount()-1 && index2 == getChildCount()-1 – csga5000 May 14 '15 at 15:20
27

to hide the child divider set it color to transparent #00000000

define transparent in your color.xml file

<color name="transparent">#00000000</color>

and then set the child divider

listView.setChildDivider(getResources().getDrawable(R.color.transparent))

or in the layout xml file

<ExpandableListView 
android:layout_width="fill_parent"
android:layout_height="fill_parent" 
android:childDivider="#00000000"/>
David-mu
  • 1,762
  • 18
  • 24
  • 10
    Setting the divider to a transparent color isn't really removing it. – 7heViking Jul 20 '14 at 09:33
  • 7
    alternatively you can use `android:childDivider="@android:color/transparent"` – cassioso Dec 19 '14 at 15:46
  • THis only works if the background behind your list is the same color as your list elements. If you have a wash color for the background and white for the elements this will not work. – Gabe Sechan Sep 27 '16 at 18:16
9

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.

Ishan Khanduja
  • 121
  • 2
  • 9
3

instead of writing lengthy code use property ExpandableListView. It will work :-

android:childDivider="@android:color/transparent" 
Imran
  • 2,906
  • 1
  • 19
  • 20
Mr.Moudgil
  • 49
  • 6
1

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);

Amit
  • 31
  • 3
0

Set the divider height of your expandableListView to 0

//setDividerHeight(0)

And then add a view at the bottom in your headerView xml

<View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_gravity="bottom"
        android:background="@android:color/darker_gray"
        />
Lilo
  • 2,724
  • 25
  • 16
-1

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"/>
Reza Zavareh
  • 187
  • 3
  • 7