@@ -36,6 +36,9 @@ public class XRefreshLayout extends FrameLayout implements NestedScrollingParent
3636 private OverScroller scroller ;
3737 private boolean isNeedInitLoadingLayout = false ;
3838
39+ boolean isRelease = false ;
40+ private boolean isSmoothScrolling = false ;
41+
3942 public XRefreshLayout (Context context ) {
4043 this (context , null );
4144 }
@@ -109,6 +112,13 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
109112 + footer .getMeasuredHeight ());
110113 }
111114
115+ @ Override
116+ public boolean dispatchTouchEvent (MotionEvent ev ) {
117+ if (isSmoothScrolling )return true ;
118+ return super .dispatchTouchEvent (ev ) ;
119+ }
120+
121+
112122 @ Override
113123 public void onNestedScrollAccepted (View child , View target , int axes ) {
114124 isRelease = false ;
@@ -118,18 +128,17 @@ public void onNestedScrollAccepted(View child, View target, int axes) {
118128 public boolean onStartNestedScroll (View child , View target , int nestedScrollAxes ) {
119129 isPullHeader = false ;
120130 isPullFooter = false ;
121- return true ;
131+ return true && ! isSmoothScrolling ;
122132 }
123133
124- boolean isRelease = false ;
125-
126134 /**
127135 * when release from XRefreshLayout!
128136 *
129137 * @param child
130138 */
131139 @ Override
132140 public void onStopNestedScroll (View child ) {
141+ L .d ("onStopNestedScroll, isPullHeader: " +isPullHeader +" isPullFooter:" +isPullFooter );
133142 isRelease = true ;
134143 if (isPullHeader ) {
135144 if (getScrollY () <= -header .getMeasuredHeight ()) {
@@ -248,9 +257,11 @@ public void scrollTo(@Px int x, @Px int y) {
248257
249258 //call percent
250259 float percent = Math .abs (y ) * 1f / header .getMeasuredHeight ();
260+ percent = Math .min (percent , 1f );
251261 if (!isRelease ){
252- loadingLayout .onPullHeader (Math . min ( percent , 1f ) );
262+ loadingLayout .onPullHeader (percent );
253263 }
264+
254265 } else if (isPullFooter ) {
255266 if (y > getFooterScrollRange ()) {
256267 y = getFooterScrollRange ();
@@ -260,6 +271,7 @@ public void scrollTo(@Px int x, @Px int y) {
260271
261272 //call percent
262273 float percent = Math .abs (y ) * 1f / footer .getMeasuredHeight ();
274+ percent = Math .min (percent , 1f );
263275 if (!isRelease ){
264276 loadingLayout .onPullFooter (Math .min (percent , 1f ));
265277 }
@@ -271,6 +283,7 @@ public void scrollTo(@Px int x, @Px int y) {
271283 @ Override
272284 public void computeScroll () {
273285 super .computeScroll ();
286+ isSmoothScrolling = isRelease && Math .abs (scroller .getCurrY ())>8 ;
274287 if (scroller .computeScrollOffset ()) {
275288 scrollTo (scroller .getCurrX (), scroller .getCurrY ());
276289 ViewCompat .postInvalidateOnAnimation (this );
0 commit comments