I want to put divider only between parent elements. When i set
android:divider="@drawable/divider"
android creates divider between parent elements, but creates divider between child elements too. When i add android:childDivider="@color/transparent"
android removes the divider between child elements, but the free space between them remains. Why?
I have tried to android:dividerHeight="0dp"
but nothing happened.
At all i want to set divider between parent elements, but i do not want any divider or empty space between child elements.
any ideas how to do that??
In order to remove dividers just from the child views and not between the parents in the expandable list:
add
android:childDivider="#00000000"
in theExapandableListView
attributes in XML:Refer this page for more information
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:
Do same in the child xml file. Add one View at the bottom of the layout with divider height and divider color that you need. Make sure divider color and height are same like in parent xml.
Into your ExpandableListView Adapter method public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) manage the state of the View divider like this: Example:
if(isExpanded){ headerDividerView.setBackgroundColor(ContextCompat.getColor(context,R.color.darker_grey)); }else{ headerDividerView.setBackgroundColor(ContextCompat.getColor(context,android.R.color.transparent)); }
BTW : In my case R.color.darker_grey is background color of the parent
Remove from your ExpandableListView xml all dividers and dividers height. Make ExpandableListView to not have dividers and divider height. You can use attrs like this :
android:groupIndicator="@null" android:childIndicator="@null" android:divider="@null" android:dividerHeight="0dp"
The trick is to create an extra
view
for collapse group layout and last child layout.collapse_group.xml:
expanded_group.xml:
And apply the same technique to the child view, for the last child view insert the extra view
Give Divider color and its height (dividers will be visible when groups are collapsed)
What I did was to set the ExpandableListView's divider to 0 and then insert "divider" groups into it's ExpandableListAdapter:
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.
Or using xml: