实现效果图:
(1)activity_main.xml,添加控件
<ExpandableListView android:id="@+id/expandable_list" android:layout_width="match_parent" android:layout_height="match_parent"/>
(2)item_expand_child.xml,这里是展开列表的布局,需要自己新建
<?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/label_expand_child" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:textSize="16sp" android:paddingTop="8dp" android:paddingBottom="8dp" tools:text="测试数据"/>
(3)item_expand_group_normal.xml,这里是默认列表的布局,需要自己新建
<?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools