@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
View v = mListView.getChildAt(0);
//当firstItem的top为0的时候就认为已经到达ListView的顶部了
if (mListView.getChildCount() > 0 && firstVisibleItem == 0) {
//滑动到顶部
if (v.getTop() == 0) {
//滑动到顶部了
isListViewTop = true;
} else {
isListViewBottom = false;
}
}else if (mListView.getChildCount()>0&&firstVisibleItem+visibleItemCount==totalItemCount){
final View bottomChildView = mListView.getChildAt(mListView.getChildCount()-1);
//当最后一个itemView的bottom>=ListView的高度的时候,那么就认为到达底部了
if (mListView.getHeight()>=bottomChildView.getBottom()){
isListViewBottom = true;
}else {
isListViewBottom = false;
}
}else {
isListViewBottom = false;
isListViewTop = false;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
touchY = ev.getRawY();
isIntercept = false;
break;
case MotionEvent.ACTION_MOVE:
float distant = ev.getRawY() - touchY;
if (isListViewTop) {
switch (mHeadPosition) {
case TOP:
if (distant > 0) isIntercept = true;
break;
case CENTER:
isIntercept = true;
break;
}
}
if (isListViewBottom){
switch (mHeadPosition) {
case CENTER:
isIntercept = true;
break;
case BOTTOM:
if (distant < 0) isIntercept = true;
break;
}
}
break;
case MotionEvent.ACTION_UP:
isIntercept = true;
break;
}
return isIntercept;
}
public static final int TOP = 0;//收缩状态 public static final int CENTER = 1;//中间状态 public static final int BOTTOM = 2;//展开状态
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
//获取不到的
break;
case MotionEvent.ACTION_MOVE:
int distant = (int) (touchY - event.getRawY());
if (getScrollY() + distant-1 < MAXY && getScrollY() + distant > 0) {
scrollTo(0, getScrollY() + distant);
}
break;
case MotionEvent.ACTION_UP:
if (getScrollY() == 0) mHeadPosition = BOTTOM;
if (getScrollY() == MAXY) mHeadPosition = TOP;
if (getScrollY() > 0 && getScrollY() < MAXY) mHeadPosition = CENTER;
if (getScrollY() > MAXY / 2) {
mScroll.startScroll(0, getScrollY(), 0, MAXY-getScrollY(),100);
invalidate();
mHeadPosition = TOP;
}
if (getScrollY() < MAXY / 2) {
mScroll.startScroll(0, getScrollY(),0,-getScrollY(),100);
invalidate();
mHeadPosition = BOTTOM;
}
break;
}
return super.onTouchEvent(event);
}
@Override
public void computeScroll() {
super.computeScroll();
if (mScroll.computeScrollOffset()){
scrollTo(mScroll.getCurrX(),mScroll.getCurrY());
postInvalidate();
}
}
if (MAXY == -1) MAXY = mHeadSecond.getMeasuredHeight();
@Override
protected void onFinishInflate() {
super.onFinishInflate();
int count = getChildCount();
//本粘性布局只支持ListView
if (count == 3 && getChildAt(2) instanceof ListView)
init();
}
/**
* 初始化
*/
private void init() {
//获得子元素
mHeadFiest = getChildAt(0);
mHeadSecond = getChildAt(1);
mListView = (ListView) getChildAt(2);
mListView.setOnScrollListener(this);
mScroll = new Scroller(getContext());
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有