I have expandablelistview and I want to add padding (or margin) between the groups items, I used margin-botton
on the group items, it works but now it is also applied to the group item and its childs, I want to keep a space between groups items, not between a group item and its child, i work like 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="match_parent"
android:orientation="vertical"
android:background="#FFFFFF">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:typeface="serif"
android:textSize="25dip"
android:textColor="#025f7c"
android:text="@string/tv_allAddresses"
android:layout_gravity="center"
android:layout_marginTop="20dip"
android:layout_marginBottom="25dip"/>
<ExpandableListView
android:id="@+id/elv_all_addresses_addresses"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dip">
</ExpandableListView>
</LinearLayout>
<?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="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/tv_all_address_group_groupName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="30dip"
android:textColor="#000000"
android:textSize="20dip"
android:typeface="serif" />
</LinearLayout>
<?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="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/tv_all_address_child_label"
android:paddingLeft="50dip"
android:typeface="serif"
android:textSize="15dip"
android:textColor="@color/BlueViolet"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tv_all_address_child_value"
android:textColor="#000000"
android:layout_marginLeft="10dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Because you are using adapter
that is extending from BaseExpandableListAdapter
so you can set padding programmatically by setting padding to group item when the group is not expanding and then remove the padding when the group is expanding and for each group set padding to last child in it.
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
if (childPosition == groups.get(groupPosition).getChilds().size() - 1) {
convertView.setPadding(0, 0, 0, 20);
} else
convertView.setPadding(0, 0, 0, 0);
return convertView;
}
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
if (isExpanded)
convertView.setPadding(0, 0, 0, 0);
else
convertView.setPadding(0, 0, 0, 20);
return convertView;
}
I assume that you are using arraylist for your groups and your childs, you can just replace the groups.get(groupPosition).getChilds().size() - 1
by the size of your group depending in your structure
I case you are looking for a better option, simply add
expandablelsv.setDividerHeight();
after the group
and child indicator
it works completely fine in my case, give it a try
check if child is last and add padding on there
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
if (isLastChild) {
convertView.setPadding(0, 0, 0, 30);
}
return convertView;
}
These two attributes helps to give space
android:divider="@android:color/transparent"
android:dividerHeight="8dp"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With