Skip to content

Instantly share code, notes, and snippets.

@CodeK1988
Created August 14, 2019 09:04
Show Gist options
  • Select an option

  • Save CodeK1988/ea0b023b91bd427cdff9573d66e3dbe6 to your computer and use it in GitHub Desktop.

Select an option

Save CodeK1988/ea0b023b91bd427cdff9573d66e3dbe6 to your computer and use it in GitHub Desktop.
VerticalOnlyNestedScrollView
/**
* thanks https://stackoverflow.com/questions/36093384/stop-nestedscrollview-inside-viewpager-to-process-horizontal-scrolls
*/
public class VerticalOnlyNestedScrollView extends NestedScrollView {
public VerticalOnlyNestedScrollView(Context context) {
super(context);
}
private float startX, startY;
public VerticalOnlyNestedScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public VerticalOnlyNestedScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (!(ev.getAction() == MotionEvent.ACTION_DOWN) && ev.getHistorySize() > 0) {
float yVector = ev.getY() - ev.getHistoricalY(0);
float xVector = ev.getX() - ev.getHistoricalX(0);
return Math.abs(yVector) + 100 <= Math.abs(xVector) || super.onTouchEvent(ev);
}
return super.onTouchEvent(ev);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment