Skip to content

Instantly share code, notes, and snippets.

@chowaikong
Created August 23, 2016 07:09
Show Gist options
  • Save chowaikong/b8de9b49eb882912b40034b4baf3cfe1 to your computer and use it in GitHub Desktop.
Save chowaikong/b8de9b49eb882912b40034b4baf3cfe1 to your computer and use it in GitHub Desktop.
InterceptScrollView, solved scroll interception problem when RecyclerView inside NestedScrollView
public class InterceptScrollView extends NestedScrollView {
private int downX;
private int downY;
private int mTouchSlop;
public InterceptScrollView(Context context) {
super(context);
mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
}
public InterceptScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
}
public InterceptScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
}
@Override public void requestChildFocus(View child, View focused) {
// super.requestChildFocus(child, focused);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
int action = ev.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
downX = (int) ev.getRawX();
downY = (int) ev.getRawY();
break;
case MotionEvent.ACTION_MOVE:
int moveY = (int) ev.getRawY();
if (Math.abs(moveY - downY) > mTouchSlop) {
return true;
}
}
return super.onInterceptTouchEvent(ev);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment