【Android】ExpandableListView二级列表使用介绍

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
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值