Reputation: 123
I would like to implement this feature to my app.
The problem is, all swipeRefreshLayouts are only for pull down gesture.
I want to swipe left / right in my recyclerView, and when I've reached maximum left, then swipe layout and show refresh like in swipeRefreshLayout.
Is it possible?
Upvotes: 3
Views: 463
Reputation: 3711
public class CustomSwipeToRefresh extends SwipeRefreshLayout {
private int mTouchSlop;
private float mPrevX;
public CustomSwipeToRefresh(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);
}
}
use this CustomSwipeToRefresh instead of SwipeRefreshLayout
Upvotes: 1