Skip to content

Instantly share code, notes, and snippets.

@DanishAmjad12
Created February 27, 2019 18:07
Show Gist options
  • Save DanishAmjad12/42aae64408600b58ad108b8834e8688d to your computer and use it in GitHub Desktop.
Save DanishAmjad12/42aae64408600b58ad108b8834e8688d to your computer and use it in GitHub Desktop.
public class MySwipeToRefresh extends SwipeRefreshLayout {
private int mTouchSlop;
private float mPrevX;
public MySwipeToRefresh (Context context, AttributeSet attrs) {
super(context, attrs);
mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mPrevX = MotionEvent.obtain(event).getX();
break;
case MotionEvent.ACTION_MOVE:
final float eventX = event.getX();
float xDiff = Math.abs(eventX - mPrevX);
if (xDiff > mTouchSlop) {
return false;
}
}
return super.onInterceptTouchEvent(event);
}
@freeapp-alex
Copy link

Hello! can you explain how it works?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment