如何删除在ExpandableListView父母和孩子之间的特定的空间 [英] How to remove specific space between parent and child in an ExpandableListView
问题描述
你能不能帮我找出为什么有本集团与孩子之间的空间?在我来说,我希望所有团体和孩子之间的空间应该是正确的组下面没有空间(但当然空间到下一组我的问题是这样的:
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 space (but of course space to the next group. My problem looks like this:
我已经设置了集团分这个绘制(expandable_list_group_divider):
I have set the Group divider 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>
和孩子分隔这个(@绘制/ expandable_list_child_divider):
And the child divider to 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>
我已经定义是这样的布局在XML(它是一种复方控制):
I have defined the layout like this in the xml(it is a compund control):
<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"/>
自定义视图类:
The 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 expandable 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:
推荐答案
这是测试并验证工作,我想回来这甚至数月以后,因为没有其它方法给我造成相当如何我希望他们。这些都显示完全OP(和我)怎么想
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
在ExpandableListView(未示出),我有分隔高度设置为0的间隔,而不是由次处理
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>
这篇关于如何删除在ExpandableListView父母和孩子之间的特定的空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!