Created
August 23, 2016 07:09
-
-
Save chowaikong/b8de9b49eb882912b40034b4baf3cfe1 to your computer and use it in GitHub Desktop.
InterceptScrollView, solved scroll interception problem when RecyclerView inside NestedScrollView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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