Can I set the distance to the start indicator for SwipeRefreshLayout?

SwipeRefreshLayout is so sensitive that when I scroll horizontally, with only a slight vertical movement, the โ€œpull to refreshโ€ indicator will be displayed. How can i avoid this? SwipeRefreshLayout has a function

public void setDistanceToTriggerSync (int distance) 

can he something like

 public void setDistanceToTriggerIndicator (int distance) 

to show the indicator only after a certain amount of vertical distance is moved down or do you guys have some work around?

Thanks!

+5
source share
1 answer

Hi @Viky I ran into the same problem as viewing the pager inside the swipe update layout, and I found that this solution is hoping it helps.

The following code is taken from this SO response :

 public class MySwipeRefreshLayout extends SwipeRefreshLayout { private int mTouchSlop; private float mPrevX; // Indicate if we've already declined the move event private boolean mDeclined; public MySwipeRefreshLayout(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(); mDeclined = false; // New action break; case MotionEvent.ACTION_MOVE: final float eventX = event.getX(); float xDiff = Math.abs(eventX - mPrevX); if (mDeclined || xDiff > mTouchSlop) { mDeclined = true; // Memorize return false; } } return super.onInterceptTouchEvent(event); } } 
+2
source

All Articles