Android 在ExpandableListView中添加组项目之间的间隙

Android 在ExpandableListView中添加组项目之间的间隙,android,android-layout,Android,Android Layout,如何在ExpandableListView中的组项目之间添加间隙(比如20dp)?我使用RelativeLayout作为父级自定义组布局。给家长增加页边空白没有帮助。不确定你的目标是什么,但这里有一个想法 将您在主要活动中获得的列表传递到自定义列表 MyExpandableListAdapter myAdapter = new MyExpandableListAdapter(expandableList); 在自定义列表类方法中: private ExpandableListView exp;

如何在
ExpandableListView
中的组项目之间添加间隙(比如20dp)?我使用
RelativeLayout
作为父级自定义组布局。给家长增加页边空白没有帮助。

不确定你的目标是什么,但这里有一个想法

将您在主要活动中获得的列表传递到自定义列表

MyExpandableListAdapter myAdapter = new MyExpandableListAdapter(expandableList);
在自定义列表类方法中:

private ExpandableListView exp;

public MyExpandableListAdapter(ExpandableListView exp)
{
    this.exp = exp;
}

public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent)
{

    if (convertView == null)
    {
        LayoutInflater infalInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(R.layout.list_child, null);
    }

    exp.setDividerHeight(0);

    return convertView;

}


public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent)
{

    if (convertView == null)
    {
        LayoutInflater infalInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(R.layout.list_row, null);
    }

    exp.setDividerHeight(20);

    return convertView;
}

例如,这应该增加组之间的间距,而不是孩子们的间距。在xml布局中,您只需将
android:dividerHeight“
添加到
ExpandableListView
中,还可以调整分隔符颜色:

       <ExpandableListView
        android:id="@+id/expandableListView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:divider="@color/red"
        android:dividerHeight="5dp"
        android:indicatorLeft="? 
        android:attr/expandableListPreferredItemIndicatorLeft"
        />


似乎我应该更仔细地阅读
ExpandableListView
规范-第二个问题,第二个一行解决方案。谢谢,这正是我需要的。我认为这不会对你有多大帮助,我只是使用expandableList太多了,而你非常welcome@Stupidus这对我有效,但在这种情况下,增加的a的颜色是灰色的,而我的列表背景是白色的,这看起来很尴尬:(……你能为我提出解决方案吗this@YSBhai是在灰色的子分隔符还是组分隔符上?还是什么是灰色的?这不起作用。它给出了随机分隔符的高度。