/**
*
*/
package com.jgx.Exlistview;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.*;
import android.view.*;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewGroup.MarginLayoutParams;
/**
* @author Jigx
*
*/
public class QExpandedListView extends ExpandableListView implements View.OnClickListener, AbsListView.OnScrollListener{
@Override
protected void dispatchDraw(Canvas canvas) {
Log.i("jgx","dispatchDraw Start");
super.dispatchDraw(canvas);
Log.i("jgx","dispatchDraw end");
}
/**
* @param context
*/
public QExpandedListView(Context context) {
super(context);
mContext = context;
this.isFixGroup = true;
super.setOnScrollListener(this);
}
/**
* @param context
* @param attrs
*/
public QExpandedListView(Context context, AttributeSet attrs) {
super(context, attrs);
mContext = context;
this.isFixGroup = true;
super.setOnScrollListener(this);
}
/**
* @param context
* @param attrs
* @param defStyle
*/
public QExpandedListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mContext = context;
this.isFixGroup = true;
super.setOnScrollListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
if(isFixGroup){//是否显示固定组头
boolean isFrameLayoutParent = getParent() instanceof RelativeLayout;
mAdapter = this.getExpandableListAdapter();
if(isFrameLayoutParent){//当前listview是放到FrameLayout的容器中
parentLayout = (RelativeLayout)getParent();
QExpandedListView listView = (QExpandedListView)view; //得到当前listview
if(null==indicatorGroup){
indicatorGroup = new LinearLayout(mContext);
indicatorGroup.setBackgroundColor(0xFFFF88AA);
parentLayout.addView(indicatorGroup, new MarginLayoutParams(LayoutParams.FILL_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT));
Log.i("iphone","indicatorGroup addView");
}
int npos = view.pointToPosition(0,0);
if(npos != AdapterView.INVALID_POSITION){
long pos = listView.getExpandableListPosition(npos);
int childPos = ExpandableListView.getPackedPositionChild(pos);
int groupPos = ExpandableListView.getPackedPositionGroup(pos);
if(childPos == AdapterView.INVALID_POSITION){
View groupView = listView.getChildAt(npos - listView.getFirstVisiblePosition());
indicatorGroupHeight = groupView.getHeight();
}
// get an error data, so return now
if(indicatorGroupHeight == 0){
return;
}
// update the data of indicator group view
if(groupPos != indicatorGroupId){
Log.e("iphone"," iphone ExListView : " + "bind to new group,group position = " + groupPos);
if(mAdapter!=null){
FixGroupView= mAdapter.getGroupView(groupPos,false,null, indicatorGroup);
indicatorGroupId = groupPos;
((exObjAdapter)mAdapter).hideGroup(indicatorGroupId); // we set this group view to be hided
((exObjAdapter)mAdapter).notifyDataSetChanged();// .notifyDataSetChanged();
}
}
}
if(indicatorGroupId == -1){
return;
}
/**
* calculate point (0,indicatorGroupHeight)
*/
int showHeight = indicatorGroupHeight;
int nEndPos = listView.pointToPosition(0,indicatorGroupHeight);
if(nEndPos != AdapterView.INVALID_POSITION){
long pos = listView.getExpandableListPosition(nEndPos);
int groupPos = ExpandableListView.getPackedPositionGroup(pos);
if(groupPos != indicatorGroupId){
View viewNext = listView.getChildAt(nEndPos-listView.getFirstVisiblePosition());
showHeight = viewNext.getTop();
//Log.e(TAG,PRE + "update the show part height of indicator group:" + showHeight);
}
}
if(FixGroupView.getParent()==null){
indicatorGroup.removeAllViews();
indicatorGroup.addView(FixGroupView);
Log.i("iphone","indicatorGroup add View");
}
// update group position
ViewGroup.LayoutParams vlparams = indicatorGroup.getLayoutParams();
if((null!=vlparams)&&(vlparams instanceof MarginLayoutParams)){
MarginLayoutParams layoutParams = (MarginLayoutParams)vlparams;
layoutParams.topMargin = -(indicatorGroupHeight-showHeight);
Log.i("iphone"," top margin:"+layoutParams.topMargin);
indicatorGroup.setLayoutParams(layoutParams);
}
else if(null!=vlparams)
{
Log.i("iphone"," layout class:"+vlparams.getClass().toString());
}
else
{
Log.i("iphone"," layout class is null");
}
}
}
if (this.mOnScrollListener != null)
this.mOnScrollListener.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount);
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (this.mOnScrollListener != null)
this.mOnScrollListener.onScrollStateChanged(view, scrollState);
}
public void setOnScrollListener(AbsListView.OnScrollListener paramOnScrollListener)
{
this.mOnScrollListener = paramOnScrollListener;
}
public void setAdapter(ExpandableListAdapter paramExpandableListAdapter)
{
super.setAdapter(paramExpandableListAdapter);
}
private RelativeLayout parentLayout=null; //listview所在的父层对象
private boolean isFixGroup=true; //是否要固定显示组名在上边
private View FixGroupView=null; //始终固定显示的组view
private ExpandableListAdapter mAdapter;
private AbsListView.OnScrollListener mOnScrollListener=null;
private int indicatorGroupId=-1; //当前固定显示的组索引
private int indicatorGroupHeight=0;
private LinearLayout indicatorGroup;
private Context mContext;
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
myexlistview.zip (36个子文件)
myexlistview
AndroidManifest.xml 680B
res
layout
member_childitem.xml 634B
member_listview.xml 968B
main.xml 524B
drawable-ldpi
icon.png 2KB
drawable
grpindicator.xml 292B
drawable-mdpi
collageicon.png 1KB
default_bg.png 111KB
icon.png 3KB
expandedicon.png 1KB
drawable-hdpi
icon.png 4KB
values
strings.xml 171B
proguard.cfg 1KB
src
com
jgx
Exlistview
dataobj.java 679B
QExpandedListView.java 6KB
exObjAdapter.java 4KB
childobj.java 263B
myexview.java 2KB
bin
com
jgx
Exlistview
dataobj.class 1KB
exObjAdapter.class 3KB
R.class 531B
childobj.class 579B
QExpandedListView.class 6KB
R$layout.class 473B
R$attr.class 340B
R$id.class 531B
R$string.class 427B
myexview.class 2KB
R$drawable.class 541B
myexlistview.apk 133KB
classes.dex 12KB
resources.ap_ 125KB
.classpath 280B
assets
default.properties 362B
.project 848B
gen
com
jgx
Exlistview
R.java 1KB
共 36 条
- 1
一叶飘舟
- 粉丝: 1w+
- 资源: 223
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页