/**
*
*/
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;
}
一叶飘舟
- 粉丝: 1w+
- 资源: 223
最新资源
- 山东联通-海信IP501H-GK6323V100C-1+8G-4.4.2-当贝桌面-卡刷包
- IMG_6338.PNG
- 典范相关分析-CCorA:R语言实现代码+示例数据
- IMG_6337.PNG
- 首发花粥商城兼容彩虹商城简介模板
- C#/WinForm演示退火算法(源码)
- 如何在 IntelliJ IDEA 中去掉 Java 方法注释后的空行.md
- C语言版base64编解码算法实现
- iflytek TextBrewer Ner任务的增强版,TextBrewer是一个基于pytorch的、为实现NLP中的知识蒸馏任务而设计的工具包
- iflytek TextBrewer Ner任务的增强版,TextBrewer是一个基于pytorch的、为实现NLP中的知识蒸馏任务而设计的工具包
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
前往页