引用:http://note.youdao.com/share/?id=994df799c2dcc8d83a8909173e42f80d&type=note

先看效果,过瘾一番。

源码下载:http://files.cnblogs.com/salam/WidgetDemo.rar

  
  ExpandableListView是Android中的手风琴,本人感觉效果相当棒。

  一、ExpandableListView介绍

    一个垂直滚动的显示两个级别(Child,Group)列表项的视图,列表项来自ExpandableListAdapter 。组可以单独展开。

  1.重要方法

      expandGroup(int groupPos) :在分组列表视图中展开一组,

      setSelectedGroup(int groupPosition) :设置选择指定的组。

      setSelectedChild(int groupPosition, int childPosition, boolean shouldExpandGroup) :设置选择指定的子项。

      getPackedPositionGroup(long packedPosition) :返回所选择的组

      getPackedPositionForChild(int groupPosition, int childPosition) :返回所选择的子项

      getPackedPositionType(long packedPosition) :返回所选择项的类型(Child,Group)

      isGroupExpanded(int groupPosition) :判断此组是否展开

  2.代码:

ExpandableListContextMenuInfo menuInfo=(ExpandableListContextMenuInfo)item.getMenuInfo();
String title=((TextView)menuInfo.targetView).getText().toString();
int type=ExpandableListView.getPackedPositionType(menuInfo.packedPosition);

if (type==ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
int groupPos =ExpandableListView.getPackedPositionGroup(menuInfo.packedPosition);
int childPos =ExpandableListView.getPackedPositionChild(menuInfo.packedPosition);

二、ExpandableListAdapter

    一个接口,将基础数据链接到一个ExpandableListView。此接口的实施将提供访问Child的数据(由组分类),并实例化的Child和Group。

  1.重要方法

    getChildId(int groupPosition, int childPosition) 获取与在给定组给予孩子相关的数据。

    getChildrenCount(int groupPosition) 返回在指定Group的Child数目。

  2.代码

public class MyExpandableListAdapter extends BaseExpandableListAdapter {
// Sample data set. children[i] contains the children (String[]) for groups[i].
public String[] groups = { "我的好友", "新疆同学", "亲戚", "同事" };
public String[][] children = {
{ "胡算林", "张俊峰", "王志军", "二人" },
{ "李秀婷", "蔡乔", "别高", "余音" },
{ "摊派新", "张爱明" },
{ "马超", "司道光" }
};

public Object getChild(int groupPosition, int childPosition) {
return children[groupPosition][childPosition];
}

public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}

public int getChildrenCount(int groupPosition) {
return children[groupPosition].length;
}

public TextView getGenericView() {
// Layout parameters for the ExpandableListView
AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, 64);

TextView textView = new TextView(ExpandableListDemo.this);
textView.setLayoutParams(lp);
// Center the text vertically
textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
// Set the text starting position
textView.setPadding(36, 0, 0, 0);
return textView;
}

public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
View convertView, ViewGroup parent) {
TextView textView = getGenericView();
textView.setText(getChild(groupPosition, childPosition).toString());
return textView;
}

public Object getGroup(int groupPosition) {
return groups[groupPosition];
}

public int getGroupCount() {
return groups.length;
}

public long getGroupId(int groupPosition) {
return groupPosition;
}

public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
ViewGroup parent) {
TextView textView = getGenericView();
textView.setText(getGroup(groupPosition).toString());
return textView;
}

public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}

public boolean hasStableIds() {
return true;
}

}

android 手风琴的更多相关文章

  1. Android开源项目库汇总

    最近做了一个Android开源项目库汇总,里面集合了OpenDigg 上的优质的Android开源项目库,方便移动开发人员便捷的找到自己需要的项目工具等,感兴趣的可以到GitHub上给个star. 抽 ...

  2. GitHub上受欢迎的Android UI Library

    GitHub上受欢迎的Android UI Library 内容 抽屉菜单 ListView WebView SwitchButton 按钮 点赞按钮 进度条 TabLayout 图标 下拉刷新 Vi ...

  3. Android UI相关开源项目库汇总

    最近做了一个Android UI相关开源项目库汇总,里面集合了OpenDigg 上的优质的Android开源项目库,方便移动开发人员便捷的找到自己需要的项目工具等,感兴趣的可以到GitHub上给个st ...

  4. GitHub 上受欢迎的 Android UI Library 整理(一)

    抽屉菜单 https://github.com/mikepenz/MaterialDrawer ★7337 - 安卓抽屉效果实现方案https://github.com/Yalantis/Side-M ...

  5. 最新最全的 Android 开源项目合集

    原文链接:https://github.com/opendigg/awesome-github-android-ui 在 Github 上做了一个很新的 Android 开发相关开源项目汇总,涉及到 ...

  6. Android中ExpandableListView的使用

    ExpandableListView是Android中可以实现下拉list的一个控件,具体的实现方法如下: 首先:在layout的xml文件中定义一个ExpandableListView < L ...

  7. android ExpandableListView详解

    ExpandableListView是android中可以实现下拉list的一个控件,是一个垂直滚动的心事两个级别列表项手风琴试图,列表项是来自ExpandableListViewaAdapter,组 ...

  8. Android(Xamarin)之旅(二)

    新的一年,新的开始,2016,我要做什么,大家要做什么,啦啦啦. OK,上篇已经介绍了几个简单的控件,这次,我们继续说说控件.但是可能有人认为这有什么难的,问题不在这里,而在于,如果你注意了每一个空间 ...

  9. 转--2014年最新810多套android源码2.46GB免费一次性打包下载

    转载自:http://www.eoeandroid.com/thread-497046-1-1.html 感谢该博客主人无私奉献~~ 下面的源码是从今年3月份开始不断整理源码区和其他网站上的安卓例子源 ...

随机推荐

  1. Thymeleaf基本知识

    Thymeleaf是个XML/XHTML/HTML5模板引擎,可以用于Web与非Web应用. Thymeleaf的主要目标在于提供一种可被浏览器正确显示的.格式良好的模板创建方式,因此也可以用作静态建 ...

  2. 在XP下安装PHP

    最近,有许多朋友问我在WindowsXp下PHP的安装过程,正好最近我在自己的机器上成功的以模块化的方式安装了PHP4.23.既然这么多朋友需要,我就以最常见的IIS和Apache服务器为例,把PHP ...

  3. iOS中的通知

    一.了解几个相关的类 1.NSNotification 这个类可以理解为一个消息对象,其中有三个成员变量. 这个成员变量是这个消息对象的唯一标识,用于辨别消息对象. @property (readon ...

  4. [LintCode] Count and Say 计数和读法

    The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221 ...

  5. set的用法

    set提供一个不重复元素的集合,一般不能直接修改元素.因为这样可能会造成重复元素因此必须删除旧元素,再插入新元素.看下面程序:分析每句的功能.#include<set>#include&l ...

  6. 使用Font Awesome替换你的网站图标

    http://fortawesome.github.io/Font-Awesome/whats-new/ 使用Font Awesome替换你的网站图标 ******************IE7BUG ...

  7. win10我能ping通他人,但他人ping不同我

    这是防火墙的原因,关闭防火墙即可

  8. CSS3初学篇章_6(自定义动画)

    自定义动画 由于有一部分低版本的浏览器并不支持的问题,所以这个样式要多做兼容,各大浏览器兼容前缀如下: 前缀 浏览器  -webkit  chrome和safari  -moz  firefox  - ...

  9. 字符串格式化命令 sprintf

    原型 int sprintf( char *buffer, const char *format, [ argument] … ); 参数列表 buffer:char型指针,指向将要写入的字符串的缓冲 ...

  10. 不正确使用WeakHashMap引起的卡死

    公司的jenkins今天出了一点问题,起来以后,总是处于等待状态,所有的任务无法正常加载.登陆界面也出不了.而且cpu占用率100% 把线程导出来,看到: “Loading job NMS_Patch ...