package com.yaxh.expandList;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.MarginLayoutParams;
import android.view.Window;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnGroupCollapseListener;
import android.widget.ExpandableListView.OnGroupExpandListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
public class SystemExpandableListActivity extends Activity implements
OnScrollListener {
// 存放父列表数据
List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
// 放子列表列表数据
List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();
ExpandableAdapter expandAdapter;
ExpandableListView expandableList;
private int indicatorGroupHeight;
private int the_group_expand_position = -1;
private int count_expand = 0;
private Map<Integer, Integer> ids = new HashMap<Integer, Integer>();
private LinearLayout view_flotage = null;
private TextView group_content = null;
private ImageView tubiao;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
initData();
// mInflater = (LayoutInflater)
// getSystemService(LAYOUT_INFLATER_SERVICE);
expandAdapter = new ExpandableAdapter(SystemExpandableListActivity.this);
expandableList = (ExpandableListView) findViewById(R.id.list);
View v = new View(this);
expandableList.addHeaderView(v);
// indicatorGroup = (LinearLayout) findViewById(R.id.topGroup);
expandableList.setAdapter(expandAdapter);
expandableList.setGroupIndicator(null);
initView();
}
private void initData() {
for (int i = 1; i <= 20; i++) {
Map<String, String> curGroupMap = new HashMap<String, String>();
groupData.add(curGroupMap);
curGroupMap.put("group_text", "Group " + i);
List<Map<String, String>> children = new ArrayList<Map<String, String>>();
for (int j = 1; j < 15; j++) {
Map<String, String> curChildMap = new HashMap<String, String>();
children.add(curChildMap);
curChildMap.put("child_text1", "Child " + j);
curChildMap.put("child_text2", "Child " + j);
}
childData.add(children);
}
}
public void initView() {
/**
* 监听父节点打开的事件
*/
expandableList.setOnGroupExpandListener(new OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
the_group_expand_position = groupPosition;
ids.put(groupPosition, groupPosition);
count_expand = ids.size();
}
});
/**
* 监听父节点关闭的事件
*/
expandableList
.setOnGroupCollapseListener(new OnGroupCollapseListener() {
@Override
public void onGroupCollapse(int groupPosition) {
ids.remove(groupPosition);
expandableList.setSelectedGroup(groupPosition);
count_expand = ids.size();
}
});
view_flotage = (LinearLayout) findViewById(R.id.topGroup);
view_flotage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
view_flotage.setVisibility(View.GONE);
expandableList.collapseGroup(the_group_expand_position);
expandableList.setSelectedGroup(the_group_expand_position);
}
});
group_content = (TextView) findViewById(R.id.content_001);
tubiao = (ImageView) findViewById(R.id.tubiao);
tubiao.setBackgroundResource(R.drawable.btn_browser2);
//设置滚动事件
expandableList.setOnScrollListener(this);
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
//防止三星,魅族等手机第一个条目可以一直往下拉,父条目和悬浮同时出现的问题
if(firstVisibleItem==0){
view_flotage.setVisibility(View.GONE);
}
// 控制滑动时TextView的显示与隐藏
int npos = view.pointToPosition(0, 0);
if (npos != AdapterView.INVALID_POSITION) {
long pos = expandableList.getExpandableListPosition(npos);
int childPos = ExpandableListView.getPackedPositionChild(pos);
final int groupPos = ExpandableListView.getPackedPositionGroup(pos);
if (childPos == AdapterView.INVALID_POSITION) {
View groupView = expandableList.getChildAt(npos
- expandableList.getFirstVisiblePosition());
indicatorGroupHeight = groupView.getHeight();
}
if (indicatorGroupHeight == 0) {
return;
}
// if (isExpanded) {
if (count_expand > 0) {
the_group_expand_position = groupPos;
group_content.setText(groupData.get(the_group_expand_position)
.get("group_text"));
if (the_group_expand_position != groupPos||!expandableList.isGroupExpanded(groupPos)) {
view_flotage.setVisibility(View.GONE);
} else {
view_flotage.setVisibility(View.VISIBLE);
}
}
if (count_expand == 0) {
view_flotage.setVisibility(View.GONE);
}
}
if (the_group_expand_position == -1) {
return;
}
/**
* calculate point (0,indicatorGroupHeight)
*/
int showHeight = getHeight();
MarginLayoutParams layoutParams = (MarginLayoutParams) view_flotage
.getLayoutParams();
// 得到悬浮的条滑出屏幕多少
layoutParams.topMargin = -(indicatorGroupHeight - showHeight);
view_flotage.setLayoutParams(layoutParams);
}
class ExpandableAdapter extends BaseExpandableListAdapter {
SystemExpandableListActivity exlistview;
@SuppressWarnings("unused")
private int mHideGroupPos = -1;
public ExpandableAdapter(SystemExpandableListActivity elv) {
super();
exlistview = elv;
}
// **************************************
public Object getChild(int groupPosition, int childPosition) {
return childData.get(groupPosition).get(childPosition)
.get("child_text1").toString();
}
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
public int getChildrenCount(int groupPosition) {
return childData.get(groupPosition).size();
}
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.childitem, null);
}
final TextView title = (TextView) view
.findViewById(R.id.child_text);
title.setText(childData.get(groupPosition).get(childPosition)
.get("child_text1").toString());
final TextView title2 = (TextView) view
.findViewById(R.id.child_text2);
title2.setText(childData.get(groupPosition).get(childPosition)
.get("child_text2").toString());
return view;
}
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
LayoutInflater inflaterGroup = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflaterGroup.inflate(R.layout.groupitem, null);
}
TextView title = (TextView) view.findViewById(R.id.content_001);
title.setText(getGroup(groupPosition).toString());
ImageView image = (ImageView) view.findViewById(R.id.tubiao);
System.out.println("isExpanded----->" + isExpanded);
if (isExpan
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
.rar (52个子文件)
可扩展列表父级悬浮
.project 856B
project.properties 360B
proguard.cfg 1KB
src
com
yaxh
expandList
SystemExpandableListActivity.java 9KB
AndroidManifest.xml 752B
res
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
user_group.png 3KB
ic_launcher.png 4KB
btn_browser2.png 2KB
default_bg.png 111KB
btn_browser.png 1KB
child_image.png 2KB
childbackground.png 3KB
drawable-mdpi
ic_launcher.png 3KB
layout
childitem.xml 1KB
groupitem.xml 2KB
main.xml 2KB
values
color.xml 105B
strings.xml 204B
.settings
org.eclipse.jdt.core.prefs 177B
org.eclipse.core.resources.prefs 88B
assets
gen
com
yaxh
expandList
BuildConfig.java 161B
R.java 2KB
.classpath 475B
bin
resources.ap_ 134KB
classes
com
yaxh
expandList
R$layout.class 463B
BuildConfig.class 347B
R$drawable.class 623B
R$attr.class 343B
SystemExpandableListActivity.class 7KB
SystemExpandableListActivity$1.class 1KB
R$id.class 690B
SystemExpandableListActivity$3.class 1KB
R.class 587B
R$string.class 430B
SystemExpandableListActivity$ExpandableAdapter.class 4KB
R$color.class 393B
SystemExpandableListActivity$2.class 1KB
AndroidManifest.xml 752B
ExpandableListDeamo2.apk 143KB
dexedLibs
annotations-f27d68383d300939a9353255e576936f.jar 943B
jarlist.cache 120B
res
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
user_group.png 3KB
ic_launcher.png 4KB
btn_browser2.png 1KB
default_bg.png 111KB
btn_browser.png 1KB
child_image.png 2KB
childbackground.png 133B
drawable-mdpi
ic_launcher.png 2KB
classes.dex 14KB
共 52 条
- 1
资源评论
群Sir
- 粉丝: 5
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 安卓11.0以上版本支持 手指单个手指双手指操作
- 电子密码锁使用说明(1).doc
- 上位机开发罗克韦尔abcip通信协议详解
- 基于去中心化联邦学习的货运速度预测时空模型-A decentralized federated learning-based s
- 适合新手的 OpenAI Sora 详细使用教程
- 驱动总裁离线安装包01
- NT98336 SDK 114版本
- torch-1.8.1+cu111-cp38-cp38-linux-x86-64.whl +torchvision
- 智能提取字幕-intel
- 计算机设计 - VB+ACCESS网络计时管理系统设计(源代码+系统),保证可靠运行,毕业生可参考,免费资源下载
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功