05.实例篇:仿QQ好友列表——ExpandableListView可扩展列表的使用(上篇)

1.前言

ListView类控件在APP中经常使用,本文主要介绍ExpandableListView,完成两级列表显示的效果。这一节(上篇、下篇)主要介绍如何仿照QQ,以及ListView和ExpandableListView的主要知识点,实现一个好友列表(静态的数据,下一节介绍如何网络上动态获取数据);

2.实现效果如下:

 实现要点:在于如何布局ChildView,以及如何定制ExpandableListView的子view, 图片资源,可以破解QQ.apk文件获取,本文末尾也会附上图片资源的;

3.实现步骤1:新建主Activity布局文件,layout/activity_expandable_list_view.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="${packageName}.${activityClass}" >

    <TextView
        android:id="@+id/txt_list_title"
        android:layout_width="match_parent"
        android:layout_height="33dp"
        android:background="@drawable/groupbar_last_bg_press"
        android:gravity="center_vertical"
        android:text="好友分组"
        android:paddingLeft="8dip"
        android:textSize="12sp" />

    <ExpandableListView
        android:id="@+id/explist_friends"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:groupIndicator="@drawable/expandable_group_bg"
        android:layout_weight="1"
        >
    </ExpandableListView>

</LinearLayout>

4.实现步骤2:新建ExpandableListView的GroupItem,ChildItem布局文件

 GroupItem布局文件:layout/expandablelist_group_item.xml
<?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="30dip"
    android:layout_gravity="center"
    android:gravity="center_vertical"
    android:background="@drawable/groupbar_bg"
    android:orientation="horizontal">
    <TextView android:id="@+id/txt_group_title"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:paddingLeft="36dip"
        android:text="我的分组"
        android:gravity="left"/>
   <TextView android:id="@+id/txt_group_num"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="0/1"
        android:paddingRight="8dip"
        android:g
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值