Skip to content

Commit 3ab8327

Browse files
author
li-xiaojun
committed
修复bug
1 parent 577c57d commit 3ab8327

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

xrefreshlayout/src/main/java/com/lxj/xrefreshlayout/XRefreshLayout.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

xrefreshlayout/src/main/java/com/lxj/xrefreshlayout/loadinglayout/DefaultLoadingLayout.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ public void onPullHeader(float percent) {
7070

7171
@Override
7272
public void onPullFooter(float percent) {
73-
L.d("footer percent : "+percent);
7473
tvFooterState.setText("释放立即加载");
7574
ivFooterArrow.setRotation(360*percent);
7675
}

xrefreshlayout/src/main/java/com/lxj/xrefreshlayout/util/L.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
public class L {
1010
private static final String TAG = "XRefreshLayout";
11-
private static boolean isDebug = true;
11+
public static boolean isDebug = false;
1212
public static void d(String msg){
1313
if(isDebug){
1414
Log.d(TAG,msg);

0 commit comments

Comments
 (0)