SwipeRefreshLayout is so sensitive that when I swipe through the screen horizontally, with only a little bit vertical movement, the "pull to refresh" indicator will show. How can I avoid this? SwipeRefreshLayout has a function
public void setDistanceToTriggerSync (int distance)
can it has something like
public void setDistanceToTriggerIndicator (int distance)
to show the indicator only after a certain amount of vertical distance is moved downwards, or do you guys have some work around?
Thanks!
If an activity wishes to show just the progress animation, it should call setRefreshing(true). To disable the gesture and progress animation, call setEnabled(false) on the view.
In this file connect the swipeRefreshLayout and textView to its XML file by using the findViewById() method. And also call the setOnRefreshListener() to change the text after the user swipe down the screen. The users can also write the required codes as their needs inside this method.
Android provides a widget that implements the swipe-to-refresh design pattern, which allows the user to trigger an update with a vertical swipe. This is implemented by the SwipeRefreshLayout widget, which detects the vertical swipe, displays a distinctive progress bar, and triggers callback methods in your app.
Hey @Viky I have faced same issue with View pager inside swipe refresh layout and I found this solution is perfect hope it help.
Following code is taken from this SO answer:
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); } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With