【发布时间】:2012-12-03 07:44:13
【问题描述】:
如何在ExpandableListView 中的组项目之间添加间隙(比如说 20dp)?我有以RelativeLayout 为父的自定义组布局。向父级添加边距没有帮助。
【问题讨论】:
如何在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;
}
例如,这应该在组之间而不是子组之间添加间距
【讨论】:
ExpandableListView 规范 - 第二个我的问题和第二个单线解决方案。谢谢,正是我需要的。
对于未来,在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"
/>
【讨论】: