Can you help me identify why there is a space between the group and the child? In my case I want spaces between all groups and the child should be right below the group with no
Set the child view programmatically like:
expandableListView.setDividerHeight(1);
expandableListView.setChildDivider(new ColorDrawable(Color.Black);
And group view From xml like :
<TextView
android:id="@+id/tv_title_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="@+id/iv_arrow"
android:layout_width="20dp"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_height="20dp"
/>
<View
android:id="@+id/header_view"
android:layout_width="match_parent"
android:layout_marginTop="10dp"
android:layout_alignParentBottom="true"
android:layout_height="1dp" />
Assuming that you want spacing between the parents, but not between parent & child. I have failed to find a proper way of achieving it. So I did a not a smart fix, by not setting the divider height, instead since I had a custom layout for every parent item, I added a LinearLayout with a fixed height of 25dp at the top of my custom parent layout, as a result I could achieve the desire functionality, but there was a side effect , when you touch the list item, the spacing as well as the list item both are highlighted on touch.
I used the following settings in the xml file and there is no gap between the parent and the child.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#f4f4f4" >
<ExpandableListView
android:id="@+id/expListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_black"
android:divider="#FF8800"
android:dividerHeight="2px" />
</RelativeLayout>
Most probably this is an issue with a margin setting you've got.
You can set Transparency between them like..
android:childDivider="@android:color/transparent"
Modify the view's padding in the method public View getChildView()
using the setPadding() method of the view.
Example:
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
View convertView, ViewGroup parentView){
final Departure departure = departures.get(groupPosition);
if(isLastChild)
expListView.setDividerHeight(DIVIDER_HEIGHT);
// Inflate childrow.xml file for child rows
convertView = inflater.inflate(R.layout.view_departure_details, parentView, false);
//Data handling...
convertView.setPadding(0, 0, 0, 0);
return convertView;
}
In the same way, if you want modify padding of the group, you will have to modify the padding in the getGroupView()
method.
Just set the child background color as same of exandableListView
example:
<ExpandableListView
android:id="@+id/expandableListView"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:indicatorLeft="@null"
android:clipChildren="true"
android:background="@color/colorGrayTransparent"
/>
and child item color like this :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:layout_marginBottom="12dp"
android:background="@color/colorGrayTransparent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
....
</LinearLayout>