• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >Android > Android中使用ExpandableListView实现微信通讯录界面(完善仿微信APP),expandablelistview

Android中使用ExpandableListView实现微信通讯录界面(完善仿微信APP),expandablelistview

作者:网友 字体:[增加 减小] 来源:互联网 时间:2017-05-26

网友通过本文主要向大家介绍了Android中使用ExpandableListView实现微信通讯录界面(完善仿微信APP),expandablelistview等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

Android中使用ExpandableListView实现微信通讯录界面(完善仿微信APP),expandablelistview


之前的博文《Android中使用ExpandableListView实现好友分组》我简单介绍了使用ExpandableListView实现简单的好友分组功能,今天我们针对之前的所做的仿微信APP来对ExpandableListView做一个扩展介绍,实现效果如下(通讯里使用ExpandableListView实现):

相关知识点博文链接:

Android中使用ExpandableListView实现好友分组

Android中Fragment和ViewPager那点事儿

Android中ListView实现图文并列并且自定义分割线(完善仿微信APP)

正常使用ExpandableListView的思路如下:

(1)要给ExpandableListView 设置适配器,那么必须先设置数据源。

(2)数据源,就是此处的适配器类ExpandableAdapter,此方法继承了BaseExpandableListAdapter ,它是ExpandableListView的一个子类。需要重写里面的多个方法。方法的意思,代码中都有详细的注释。数据源中,用到了自定义的View布局,此时根据自己的需求,来设置组和子项的布局样式。getChildView()和getGroupView()方法设置自定义布局。
(3)数据源设置好,直接给 ExpandableListView.setAdapter()即可实现此收缩功能。

但本次实现除以上实现步骤之外,还需要注意的有以下几点:

(1)首次加载ExpandableListView需要默认全部展开,使用以下方法: 在给ExpandableListView 设置适配器后,添加以下代码:
1 //Group.size()为组名个数,如果为数组存储则为group、length
2 for (int i = 0; i < Group.size(); i++) { 
3     expandableListView.expandGroup(i); 
4 } 
提醒:加载前别忘了判断adapter是否为空和有没有Group数据哦

(2)保持ExpandableListView始终展开无法收缩

1 expandableListView.setOnGroupClickListener(new OnGroupClickListener() {
2     @Override
3     public boolean onGroupClick(ExpandableListView parent, View v,
4         int groupPosition, long id) {
5         return true;//返回true则表示无法收缩
6     }
7 });
(3)取消通讯录上方的groupName空间 微信通讯录中“新的朋友”,“群聊”,“标签”,“公众号”,作为一个整体自定义布局添加到ExpandableListView中,详情见以下代码实现 (4)修改ExpandableListView的分割线 大概思路就是这样,现在开始整体实现代码的演示:

第一步:layout中通讯录整体布局contactfragment.xml:

其实就是一个ExpandableListView,添加android:divider ="#FFFFFF"取消自带分割线

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:orientation="vertical" android:layout_width="match_parent"
 4     android:layout_height="match_parent"
 5     android:background="@color/fragmentback">
 6     <ExpandableListView
 7         android:id="@+id/contact_list"
 8         android:layout_width="match_parent"
 9         android:layout_height="match_parent"
10         android:layout_alignParentTop="true"
11         android:layout_alignParentStart="true"
12         android:divider ="#FFFFFF"/>
13 </LinearLayout>

第二步:layout中组名(groupName)的布局文件contact_list_group_item.xml:

注意设置间距,保证美观且尽量与微信一致

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:orientation="vertical" android:layout_width="match_parent"
 4     android:layout_height="match_parent"
 5     android:background="@color/fragmentback">
 6     <TextView
 7         android:text="TextView"
 8         android:textSize="20sp"
 9         android:layout_width="match_parent"
10         android:layout_height="wrap_content"
11         android:layout_marginLeft="10dp"
12         android:gravity="center_vertical"
13         android:id="@+id/group_tv" />
14 </LinearLayout>

第三步:layout中ExpandableListView中每个item的布局文件contact_list_item.xml:

这里添加了自定义分割线
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:orientation="vertical" android:layout_width="match_parent"
 4     android:layout_height="match_parent">
 5     <LinearLayout
 6         android:background="@color/colorwhite"
 7         android:layout_width="match_parent"
 8         android:layout_height="match_parent"
 9         android:orientation="vertical">
10         <LinearLayout
11             android:paddingLeft="10dp"
12             android:paddingTop="5dp"
13             android:paddingBottom="5dp"
14             android:gravity="center_vertical"
15             android:layout_width="match_parent"
16             android:layout_height="wrap_content"
17             android:orientation="horizontal">
18             <ImageView
19                 android:id="@+id/contact_item_iv"
20                 android:layout_width="wrap_content"
21                 android:layout_height="wrap_content"
22                 android:src="@mipmap/default_fmessage"
23                 android:adjustViewBounds="true"
24                 android:maxWidth="35dp"/>
25             <TextView
26                 android:id="@+id/contact_item_tv"
27                 android:layout_margin="10dp"
28                 android:layout_width="0dp"
29                 android:layout_height="wrap_content"
30                 android:layout_weight="1"
31                 android:text="新的朋友"/>
32         </LinearLayout>
33         <View
34             android:layout_width="match_parent"
35             android:layout_height="1dp"
36             android:layout_marginLeft="10dp"
37             android:layout_marginRight="10dp"
38             android:background="@color/fragmentback"/>
39     </LinearLayout>
40 </LinearLayout>

第四步:layout中ExpandableListView中的头布局contact_list_title.xml(不需要groupName)

我们观察微信通讯录布局中“新的朋友”,“群聊”,“标签”,“公众号”上方直接为微信的顶部导航,不存在ExpandableListView一贯的组名布局,这里我们将 “新的朋友”,“群聊”,“标签”的布局单独实现:
  1 <?xml version="1.0" encoding="utf-8"?>
  2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3     android:orientation="vertical" android:layout_width="match_parent"
  4     android:layout_height="match_parent">
  5         <LinearLayout
  6             android:background="@color/colorwhite"
  7             android:layout_width="match_parent



 
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • Android中使用ExpandableListView实现微信通讯录界面(完善仿微信APP),expandablelistview

相关文章

  • 2017-05-26Android 第一http请求访问慢,以后就快了的问题,android请求
  • 2017-05-26android开发之路05,android之路05
  • 2017-05-222.3.7 ProgressBar(进度条)
  • 2017-05-26Android之侧滑导航栏,android滑导航栏
  • 2017-05-26React Native 出现红屏幕报连接服务失败,reactnative
  • 2017-05-26安卓的主要几大布局,安卓布局
  • 2017-05-26Android 几种消息推送方案总结,android方案
  • 2017-05-26Android开发:消息机制简述
  • 2017-05-26View控件中android:drawablePadding不起作用的原因探究,
  • 2017-05-26Android应用程序安装过程浅析

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • 【方法总结】创建、读取、删除文件相关操作,读取删除文件
    • Android中Activity处理返回结果的实现方式,androidactivity
    • Android Git 客户端,androidgit客户端
    • 我的android学习经历16,android学习经历16
    • 【Android】常见问题解答,android
    • 浅谈Kotlin(二):基本类型、基本语法、代码风格,浅谈kotlin
    • 一起来学习Android自定义控件
    • 统计nginx日志中各服务(目录)http总请求数、成功数、失败数的shell
    • Android热补丁动态修复技术(二):实战!CLASS_ISPREVERIFIED问题!
    • Android 7.0(牛轧糖)新特性,android牛轧糖

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有