Created
February 27, 2019 18:07
-
-
Save DanishAmjad12/42aae64408600b58ad108b8834e8688d to your computer and use it in GitHub Desktop.
This file contains 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 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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello! can you explain how it works?