• 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实现好友分组,expandablelistview

Android中使用ExpandableListView实现好友分组,expandablelistview

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

网友通过本文主要向大家介绍了expandablelistview,xexpandablelistview,android仿qq好友列表,android 好友列表,android qq好友列表等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

Android中使用ExpandableListView实现好友分组,expandablelistview


一个视图显示垂直滚动两级列表中的条目。这不同于列表视图,允许两个层次,类似于QQ的好友分组。要实现这个效果的整体思路为:

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

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

3.数据源设置好,直接给ExpandableListView.setAdapter()即可实现此收缩功能。

下面是我自己简单做的一个显示效果:

layout中主视图expandable_layout.xml(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     <ExpandableListView
 6         android:layout_width="match_parent"
 7         android:layout_height="match_parent"
 8         android:id="@+id/el">
 9     </ExpandableListView>
10 </LinearLayout>

 

Layout中group_layout.xml(分组组名展示布局):

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     xmlns:app="http://schemas.android.com/apk/res-auto"
 4     android:orientation="horizontal" android:layout_width="wrap_content"
 5     android:layout_height="wrap_content"
 6     android:gravity="center_vertical">
 7     <ImageView
 8         android:layout_width="wrap_content"
 9         android:layout_height="wrap_content"
10         app:srcCompat="@mipmap/ic_launcher"
11         android:id="@+id/iv_group" />
12     <TextView
13         android:text="TextView"
14         android:layout_width="wrap_content"
15         android:layout_height="wrap_content"
16         android:id="@+id/tv_group" />
17 </LinearLayout>

Layout中child_layout.xml(子菜单item布局):

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     xmlns:app="http://schemas.android.com/apk/res-auto"
 4     android:orientation="horizontal" android:layout_width="wrap_content"
 5     android:layout_height="wrap_content"
 6     android:gravity="center_vertical"
 7     android:paddingLeft="50dp">
 8     <ImageView
 9         android:layout_width="wrap_content"
10         android:layout_height="wrap_content"
11         app:srcCompat="@mipmap/ic_launcher"
12         android:id="@+id/iv_item" />
13     <TextView
14         android:text="TextView"
15         android:layout_width="wrap_content"
16         android:layout_height="wrap_content"
17         android:id="@+id/tv_item" />
18 </LinearLayout>

Layout中alertdialog_layout.xml(AlertDialog自定义显示布局):

 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     <EditText
 6         android:layout_width="match_parent"
 7         android:layout_height="wrap_content"
 8         android:id="@+id/et"
 9         android:hint="请输入想对他说的话"/>
10 </LinearLayout>

Activity中Java实现代码(ExpandableListViewDemo.java):

 

  1 import android.content.DialogInterface;
  2 import android.os.Bundle;
  3 import android.support.annotation.Nullable;
  4 import android.support.v7.app.AlertDialog;
  5 import android.support.v7.app.AppCompatActivity;
  6 import android.view.View;
  7 import android.view.ViewGroup;
  8 import android.widget.BaseExpandableListAdapter;
  9 import android.widget.ExpandableListView;
 10 import android.widget.ImageView;
 11 import android.widget.TextView;
 12 import android.widget.Toast;
 13 /**
 14  * Created by panchengjia on 2016/12/2.
 15  */
 16 public class ExpandableListViewDemo extends AppCompatActivity {
 17     ExpandableListView el;
 18     //定义分组名以及对应的图片数组,需一一对应
 19     String[] country={"魏国","蜀国","吴国"};
 20     int[] icon={R.mipmap.wei,R.mipmap.shu,R.mipmap.wu};
 21     //使用二维定义组内成员以及对应头像,同样需要以一一对应
 22     String[][] heros={{"司马懿","郭嘉","夏侯惇","甄姬"},{"刘备","赵云","张飞"},{"孙权","周瑜"}};
 23     int[][] icons={{R.mipmap.simayi,R.mipmap.guojia,R.mipmap.xiahoudun,R.mipmap.zhenji},
 24             {R.mipmap.liubei,R.mipmap.zhaoyun,R.mipmap.zhangfei},{R.mipmap.sunquan,R.mipmap.zhouyu}};
 25     @Override
 26     protected void onCreate(@Nullable Bundle savedInstanceState) {
 27         super.onCreate(savedInstanceState);
 28         setContentView(R.layout.expandable_layout);
 29         el= (ExpandableListView) findViewById(R.id.el);
 30         //设置点击下拉子菜单的监听事件
 31         el.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
 32             @Override
 33             public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, <



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

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

  • Android中使用ExpandableListView实现微信通讯录界面(完善仿微信APP),expandablelistview
  • Android中使用ExpandableListView实现好友分组,expandablelistview
  • 可展开的列表组件——ExpandableListView深入解析,expandablelist展开
  • 安卓开发树形控件之ExpandableListView(一),expandablelistview
  • Android ExpandableListView相关介绍
  • 【原创】Android ExpandableListView使用,expandablelistview

相关文章

  • 2017-07-22Android深入四大组件(四)广播的注册、发送和接收过程
  • 2017-05-26关于视频编辑SDK的接入说明,视频编辑sdk接入
  • 2017-05-26安卓GreenDao框架一些进阶用法整理,安卓greendao
  • 2017-05-26Android 手机卫士--9patch图,
  • 2017-05-26安卓界面组件----时间日期拾取器,安卓拾取
  • 2017-05-26Android属性动画
  • 2017-05-26注册时获取验证码常用的倒计时工具,注册时验证码
  • 2017-05-26easy touch利用playmaker拖动ngui对象
  • 2017-05-26安卓第十三天笔记-服务(Service),安卓第十三天
  • 2017-05-26Android Volley框架的使用(4),androidvolley

文章分类

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

最近更新的内容

    • Android安全攻防战,反编译与混淆技术完全解析(上)
    • 绘制视图,根据轴测图绘制三视图
    • 两个Service之间相互监视的实现,两个service监视
    • AndroidStudio如何快速制作.so
    • 开源插件 PullToRefresh: PullToRefreshListView / PullToRefreshGridView 实例详解
    • Android_安卓为按钮控件绑定事件的五种方式,android按钮控件
    • win7系统连接WiFi上网信号很弱怎么办
    • 硅谷新闻9--图片三级缓存,
    • 【读书笔记】【Android 开发艺术探索】第3章 View 的事件体系
    • 首页3--界面上拉下拉的回弹效果,3--拉下

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

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