Jongz Puangput Jongz Puangput - 1 month ago 24
Android Question

SwipeRefreshLayout - swipe down to refresh but not move the view pull down

Is it possible ?? as a Title said

swipe down to refresh Layout but stick the Layout not move it down along swipe gusture

Thank you - I'm using SwipeRefreshLayout

Answer

After my trial and error, I found one solution from

http://www.dailydevbook.de/android-swiperefreshlayout-without-overscroll/

For people who can implement SwipeRefreshLayout, in order to achieve it


STEP 1: DOWNLOAD android-support v4 (Open Source) from github

STEP 2: COPY following java class to your project src

  • SwipeRefreshLayout
  • SwipeProgressBar
  • BakedBezierInterpolator

note1- (Refactor SwipeRefreshLayout to mySwipeRefreshLayout to prevent confusing with original) note2- (Fix these classes and use the source from each other instead of v4)

STEP 3: UPDATE CODE use

  • mySwipeRefreshLayout instead of
  • SwipeRefreshLayout

STEP 4: UPDATE LAYOUT use

  • com.yourpackage.mySwipeRefreshLaout instead of
  • android.support.v4.widget.SwipeRefreshLayout

STEP 5: In your mySwipeRefreshLayout.java, find and change to a following code

private  void  updateContentOffsetTop ( int  targetTop) {
        final  int  currentTop = mTarget.getTop ();
        if  (targetTop> mDistanceToTriggerSync) {
            targetTop = ( int ) mDistanceToTriggerSync;
        } else  if  (targetTop < 0 ) {
            targetTop = 0 ;
        }
        // SetTargetOffsetTopAndBottom (targetTop - currentTop);
        setTargetOffsetTopAndBottom ( 0 ); // MOD: Prevent Scroll Down Animation
    }