SoFunction
Updated on 2025-04-08

Solution to the conflict between SwipeRefreshLayout and ViewPager sliding event in Android

Solution to the conflict between SwipeRefreshLayout and ViewPager sliding event in Android

Problem description:

During development, it was found that the pull-down refresh of SwipeRefreshLayout conflicts with the left and right sliding event of the banner developed by ViewPager, causing the banner's left and right sliding is not smooth enough. It is easy to trigger the pull-down refresh of SwipeRefreshLayout during the slide left and right of the banner, resulting in a poor experience of sliding left and right of the banner.

Solution:

SwipeRefreshLayout can be set to be temporarily unavailable when viewPager is sliding, and the sliding effect of ViewPager becomes very smooth.

Code example:

(new () { 
         @Override 
         public boolean onTouch(View v, MotionEvent event) { 
           switch (()) { 
             case MotionEvent.ACTION_MOVE: 
               (false); 
               break; 
             case MotionEvent.ACTION_UP: 
             case MotionEvent.ACTION_CANCEL: 
               (true); 
               break; 
           } 
           return false; 
         } 
       }); 

Thank you for reading, I hope it can help you. Thank you for your support for this site!