Search code examples
androidlistviewandroid-listviewexpandablelistviewseparator

childDivider's width in ExpandableListView


I have this ExpandableListView:

<ExpandableListView
  android:id="@+id/pizzaList"
  android:layout_width="match_parent"
  android:layout_height="0dp"
  android:layout_weight="1"
  android:groupIndicator="@null"
  android:divider="@color/cacaca"
  android:dividerHeight="1dp">
</ExpandableListView>

@color/cacaca is:

<item name="cacaca" type="color">#cacaca</item>

The problem is the width of divider is match_parent by default, but there is not a dividerWidth. How can I change this value ?

A screenshot:

image

Minium API is: 10 2.3.3 Target: 15

Thank you!!!


Solution

  • You can change the divider's width by creating your own class extending the ExpandableListView, and overwrite its onDraw() method, where you can specify custom measurements to it.

    You can opt for a workaround too: set the divider to @null, and create a custom view to your renderers, with a horizontal line (view) at the bottom of each ViewGroup. You can assign the width you wish to this view, and it will look as a divider.

    The second approach may be easier to go for, but I it's pricier too in terms of memory usage / layout speed.