How to remove specific space between parent and child in an ExpandableListView

后端 未结 10 2183
太阳男子
太阳男子 2021-02-20 09:10

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

相关标签:
10条回答
  • 2021-02-20 09:52

    In order to remove dividers just from the child views and not between the parents in the expandable 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/

    0 讨论(0)
  • 2021-02-20 09:54

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

    <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 some people consider it a bad practice to use negative margin but right it seems to be the easiest way.

    Other way(the time-consuming way) is to implement you own expandable listview so that you have more control on how things are drawn.

    0 讨论(0)
  • 2021-02-20 09:57

    Remove all the margins and divider height, and instead add a blank space on top of groupview itself. It should do the trick.

    0 讨论(0)
  • 2021-02-20 10:01

    this is tested and is proven to work, i wanted to come back to this even months later because none of the other methods gave me results quite how i wanted them. these are displayed exactly how OP (and myself) wanted

    this is my groups or categories or whatever. basically the first linear layout is just a wrapper for a view which acts as a spacer between the categories, and then another linear layout that handles all my formatting

    in the ExpandableListView(not shown) i have the divider height set to 0. the spacing is instead handled 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 child i have this.

    <?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>
    
    0 讨论(0)
提交回复
热议问题