public class InnerScrollView extends ScrollView {
public InnerScrollView (Context context) {
super(context);
}
public InnerScrollView (Context context) {
super(context);
}
public InnerScrollView (Context context, AttributeSet attrs) {
super(context, attrs);
}
public InnerScrollView (Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
//在Y轴上可以滑动的最大距离 = 总长度 - 当前展示区域长度
private int maxY =0;
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
maxScrollY=getChildAt(0).getMeasuredHeight() - getHeight();
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
getParent().getParent().requestDisallowInterceptTouchEvent(true);
break;
case MotionEvent.ACTION_MOVE:
if (getScrollY() > 0 && getScrollY() < maxY)
getParent().requestDisallowInterceptTouchEvent(true);
else
getParent().requestDisallowInterceptTouchEvent(false);
/*if (getScrollY()==0)
Log.i("kkk","滑到头了");
if (getChildAt(0).getMeasuredHeight() == getScrollY() + getHeight())
Log.i("kkk","滑到底了");*/
break;
case MotionEvent.ACTION_UP:
getParent().getParent().requestDisallowInterceptTouchEvent(false);
break;
}
return super.dispatchTouchEvent(ev);
}
}