• 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 > 可展开的列表组件——ExpandableListView深入解析,expandablelist展开

可展开的列表组件——ExpandableListView深入解析,expandablelist展开

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

网友通过本文主要向大家介绍了expandablelistview,xexpandablelistview,e路护航网银安全组件,菜鸟打印组件,ca浏览器组件下载等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

可展开的列表组件——ExpandableListView深入解析,expandablelist展开


可展开的列表组件——ExpandableListView深入解析

一、知识点 
1、ExpandableListView常用XML属性 
2.ExpandableListView继承BaseExpandableListAdapter后重写的各个函数详解 
3.ExpandableListView自定义下拉图标

二、解析 
2.1、ExpandableListView常用XML属性

2.1.1 设置点击item项后该item项的背景色

//当你选中某一个item项时,该item项的背景会变色,下面的值是将该背景色设置为透明

android:listSelector="#00000000"

2.1.2 设置item项的高度

//这个是用在item的布局文件里
android:minHeight="50dp"

2.1.3 拖动时背景图片问题

//在拖动的时候背景图片消失变成黑色背景,等到拖动完毕我们自己的背景图片才显示出来
android:scrollingCache=”false” 
或 android:cacheColorHint=”#00000000″

2.1.4 分割线高度

android:dividerHeight="1dp"

2.2ExpandableListView继承BaseExpandableListAdapter后重写的各个函数详解

下面的代码几乎每条都给了注释,就不再赘述了。

2.2.1 child.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="50dp"
    android:orientation="horizontal" >

    <TextView 
        android:id="@+id/tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_marginLeft="10dp"
        android:textSize="18dp"
        android:text="this"
        />

</LinearLayout>

2.2.2 group.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="wrap_content"
    android:minHeight="50dp"
    android:orientation="horizontal" >
    <ImageView
        android:layout_marginLeft="10dp"
        android:layout_gravity="center_vertical"
        android:id="@+id/arrow"
        android:layout_width="25dp"
        android:layout_height="25dp"
        />
    <TextView 
        android:layout_marginLeft="10dp"
        android:id="@+id/logo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20dp"
        android:layout_gravity="center_vertical"
        />
</LinearLayout>

2.2.3 colors.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="gray">#BEBEBE</color>
    <color name="SeaGreen1">#54FF9F</color>
</resources>

2.2.4 activity_main.xml

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"

    >
    <ExpandableListView 
        android:id="@+id/expandlist"
        android:divider="@color/gray"
        android:childDivider="@color/SeaGreen1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:groupIndicator="@null"
        android:listSelector="#00000000"
        android:dividerHeight="1dp"
        >

    </ExpandableListView>
</LinearLayout>

2.2.5 MyExpandableListAdapter.java

package com.yds.example;


import java.util.List;
import java.util.Map;

import android.content.Context;
import android.database.DataSetObserver;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MyExpandableListAdapter extends BaseExpandableListAdapter {
    //上下文
    Context context;
    //声明一个布局管理器对象
    LayoutInflater inflater;
    //声明一个组集合
    List<Map<String, Object>>group;
    //声明一个子元素集合
    List<List<Map<String, Object>>>child;
    //声明一个map对象
    Map<String, Object>map;
    /**
     * 自定义适配器的构造函数
     * @param context 上下文
     * @param group 组集合
     * @param child 子元素集合
     */
    public MyExpandableListAdapter(Context context,List<Map<String, Object>>group,List<List<Map<String, Object>>>child){
        //初始化上下文
        this.context = context;
        //初始化布局管理器对象
        inflater = LayoutInflater.from(context);
        //初始化组集合
        this.group = group;
        //初始化子元素集合
        this.child = child;
    }
    /**
     * ExpandableListAdapter里面的所有条目
     * 都可用吗?如果是yes,就意味着所有条目可以选择和点击了。
     * 返回值



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

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

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

相关文章

  • 2017-05-26Linux主机网络流量监控ifstat
  • 2017-05-22.5.9 AlertDialog(对话框)详解
  • 2017-05-26Android自定义下拉刷新动画--仿百度外卖下拉刷新
  • 2017-05-26Android中使用ViewPager实现屏幕页面切换和页面轮播效果,androidviewpager
  • 2017-05-26组件RecyclerView的应用(一),组件recyclerview
  • 2017-05-26基于android-async-http的android服务,android-async-http
  • 2017-05-224.4.1 ContentProvider初探
  • 2017-05-26android自定义activity,androidactivity
  • 2017-05-26工厂模式--实战详解,--实战详解
  • 2017-05-26Android中BroadcastReceiver的两种注册方式(静态和动态)详解,broadcastreceiver

文章分类

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

最近更新的内容

    • Android中TextView添加删除线,androidtextview
    • Android应用程序安装过程浅析
    • 向量时钟算法简介
    • linux 内存性能调优
    • 2.6.1 PopupWindow(悬浮框)的基本使用
    • Android中使用ViewPager实现屏幕页面切换和页面轮播效果,androidviewpager
    • Android 在Android代码中执行命令行,android命令行
    • Android Studio 2.2.2导入Eclipse中创建的项目,androideclipse
    • android滚动公告栏,android公告栏
    • zoom动画,实现图片点击预览效果,zoom预览

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

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