ExpandableListView是一个用于垂直滚动展示二级列表的视图,与ListView不同的是它可以展示二级列表,分组可以 单独展开子选项。这些选项数据是通过ExpandableListView关联的。
创建布局文件
<ExpandableListView
android:layout_width="match_parent"
android:layout_height="match_parent">
</ExpandableListView>
上述是简单的布局文件使用,同时也可以添加如下属性:
android:childDivider:制定各组内子类表项之间的分隔条,分隔表是一条直线
android:childDivider:制定各组内子类表项之间的分隔条,分隔表是一条直线
android:childIndicator:显示在子列表左边的Drawable对象,可以是一个图像
android:childIndicatorEnd:子列表指示符的结束约束位置
android:childIndicatorLeft:子列表指示符的左边约束位置
android:childIndicatorRight:子列表指示符的右边约束位置
android:childIndicatorStart:子列表指示符的开始约束位置
android:groupIndicator:显示在组列表旁边的DrawAble对象,可以是一个图像
android:indicatorEnd:组列表指示符的结束约束位置
android:indicatorLeft:组列表指示符的左边约束位置
android:indicatorRight:组列表指示符的右边约束位置
android:indicatorStart:组列表指示符的开始约束位置
父项布局文件:
<?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:paddingBottom="8dp"
android:paddingTop="8dp">
<TextView
android:id="@+id/tv_item_list_group_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:text="文件夹"
android:textAppearance="@style/TextAppearance.AppCompat.Title" />
</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="wrap_content"
android:layout_marginLeft="5dp"
android:orientation="horizontal"
android:paddingLeft="16dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_margin="8dp">
<View
android:id="@+id/v_list_item_priority"
android:layout_width="5dp"
android:layout_height="18dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="@color/colorWhite" />
<TextView
android:id="@+id/tv_list_item_list_name"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
an