How to remove specific space between parent and child in ExpandableListView

Can you help me determine why there is space between the group and the child? In my case, I want the spaces between all groups and the child to be directly below the group without spaces (but, of course, the space for the next group. My problem looks like this: enter image description here

I set the Group delimiter to this drawable (expandable_list_group_divider):

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <size android:height="10dp"/> </shape> 

And a child divider for this (@ drawable / expandable_list_child_divider):

 <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <size android:height="0dp"/> </shape> 

I defined a layout similar to this in xml (this is comprehensive management):

 <com.jws.MyExpandableListView android:id="@+id/expList" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:layout_marginLeft="15dp" android:layout_marginRight="15dp" android:scrollbars="none" android:divider="@drawable/expandable_list_group_divider" android:childDivider="@drawable/expandable_list_child_divider"/> 

Custom view class:

 public class MyExpandableListView extends ExpandableListView { protected ArrayList<Departure> departures; public MyExpandableListView(Context context, AttributeSet attrs) { super(context, attrs); setGroupIndicator(null); setChildIndicator(null); setHorizontalFadingEdgeEnabled(true); setVerticalFadingEdgeEnabled(true); setFadingEdgeLength(60); departures = new ArrayList<Departure>(); this.setAdapter(new MyExpandableListAdapter(context, this, departures)); } } 

And finally, the extensible list adapter

 public class DeparturesExpandableListAdapter extends BaseExpandableListAdapter { private final int DIVIDER_HEIGHT = 20; private LayoutInflater inflater; private ArrayList<Departure> departures; private Context context; private ExpandableListView expListView; public DeparturesExpandableListAdapter(Context context, ExpandableListView expListView, ArrayList<Departure> departures) { this.context = context; inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE); this.departures = departures; this.expListView = expListView; } // This Function used to inflate parent rows view @Override public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parentView) { final Departure departure = departures.get(groupPosition); if(!isExpanded) expListView.setDividerHeight(DIVIDER_HEIGHT); else expListView.setDividerHeight(-4); expListView.setFooterDividersEnabled(false); // Inflate grouprow.xml file for parent rows convertView = inflater.inflate(R.layout.view_departure_overview, parentView, false); //Data handling in the view... return convertView; } // This Function used to inflate child rows view @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... return convertView; } @Override public Object getChild(int groupPosition, int childPosition) { return departures.get(groupPosition); } //Call when child row clicked @Override public long getChildId(int groupPosition, int childPosition) { return childPosition; } @Override public int getChildrenCount(int groupPosition) { return 1; } @Override public Object getGroup(int groupPosition) { return departures.get(groupPosition); } @Override public int getGroupCount() { if(departures != null) return departures.size(); return 0; } //Call when parent row clicked @Override public long getGroupId(int groupPosition) { return groupPosition; } @Override public void notifyDataSetChanged() { // Refresh List rows super.notifyDataSetChanged(); } @Override public boolean isEmpty() { return ((departures == null) || departures.isEmpty()); } @Override public boolean isChildSelectable(int groupPosition, int childPosition) { return false; } @Override public boolean hasStableIds() { return false; } @Override public boolean areAllItemsEnabled() { return true; } } 

Image for comments: enter image description here

+8
java android expandablelistview
source share
9 answers

it is checked and proved that it works, I wanted to return to this even after a few months, because none of the other methods gave me the results as I wanted them. they are displayed exactly as OP (and I) wanted

these are my groups or categories or something else. basically the first linear layout is just a presentation wrapper that acts as a separator between categories, and then another linear layout that handles all my formatting

in ExpandableListView (not shown), I have set the divider height to 0. The interval is instead processed by the views

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical"> <View android:layout_width="fill_parent" android:layout_height="6dp" android:background="@android:color/transparent"/> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:padding="8dp" android:background="#50601CBA"> <TextView android:id="@+id/lblListHeader" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:textSize="17dp" android:textColor="#FFFFFF" /> </LinearLayout> </LinearLayout> 

then in the subsidiary I have it.

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="55dip" android:orientation="vertical" > <TextView android:id="@+id/lblListItem" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="12sp" android:paddingTop="5dp" android:paddingBottom="5dp" android:textColor="#FFFFFF" android:background="#50601CBA" /> </LinearLayout> 
+4
source share

I used the following parameters in the xml file, and there is no gap between parent and 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 likely, this is a problem with setting up the margin.

+3
source share

Remove all fields and the height of the separator and instead add blank space on top of the group view itself. That should do the trick.

+2
source share

To remove separators only from child views, and not between parents in an extensible list:

add android: childDivider = "# 00000000" in the ExapandableListView attributes in XML:

 <ExpandableListView android:id="@+id/elv" android:layout_width="match_parent" android:layout_height="wrap_content" android:childDivider="#00000000" android:dividerHeight="0dp" /> 

Refer http://qtcstation.com/2011/03/working-with-the-expandablelistview-part-1/

+2
source share

Assuming you want to set the distance between parents, but not between parents and children. I could not find the right way to achieve it. So I made an unreasonable correction without setting the height of the separator, instead, since I had my own layout for each parent element, I added a LinearLayout with a fixed height of 25 dp at the top of my custom parent layout, as a result I could achieve desired functionality, but there was a side effect when you touch a list item, an interval, and also a list item are both highlighted when touched.

+2
source share

Use negative margin for child view in view_departure_details. Something like that:

 <TextView android:id="text1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="-10dp" android:text="@string/my_best_text" android:background="#FF0000" /> 

I know that some people find it bad practice to use a negative margin, but it seems to be the easiest way.

Another way (time-consuming way) is to implement your own extensible list so that you can have more control over how the drawings are made.

+2
source share

Set the child view programmatically as follows:

expandableListView.setDividerHeight (1);

expandableListView.setChildDivider (new ColorDrawable (Color.Black);

And group view From xml:

  <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" /> 
0
source share

You can set the transparency between them as ..

  android:childDivider="@android:color/transparent" 
0
source share

Change the view padding in the public View getChildView() method using the setPadding () view method.

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 to change the complement of a group, you have to change the addition in the getGroupView() method.

0
source share

All Articles