Skip to content

Commit

Permalink
修复bug
Browse files Browse the repository at this point in the history
  • Loading branch information
li-xiaojun committed May 4, 2017
1 parent 577c57d commit 3ab8327
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public class XRefreshLayout extends FrameLayout implements NestedScrollingParent
private OverScroller scroller;
private boolean isNeedInitLoadingLayout = false;

boolean isRelease = false;
private boolean isSmoothScrolling = false;

public XRefreshLayout(Context context) {
this(context, null);
}
Expand Down Expand Up @@ -109,6 +112,13 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
+ footer.getMeasuredHeight());
}

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if(isSmoothScrolling)return true;
return super.dispatchTouchEvent(ev) ;
}


@Override
public void onNestedScrollAccepted(View child, View target, int axes) {
isRelease = false;
Expand All @@ -118,18 +128,17 @@ public void onNestedScrollAccepted(View child, View target, int axes) {
public boolean onStartNestedScroll(View child, View target, int nestedScrollAxes) {
isPullHeader = false;
isPullFooter = false;
return true;
return true && !isSmoothScrolling;
}

boolean isRelease = false;

/**
* when release from XRefreshLayout!
*
* @param child
*/
@Override
public void onStopNestedScroll(View child) {
L.d("onStopNestedScroll, isPullHeader: "+isPullHeader +" isPullFooter:"+isPullFooter );
isRelease = true;
if (isPullHeader) {
if (getScrollY() <= -header.getMeasuredHeight()) {
Expand Down Expand Up @@ -248,9 +257,11 @@ public void scrollTo(@Px int x, @Px int y) {

//call percent
float percent = Math.abs(y) * 1f / header.getMeasuredHeight();
percent = Math.min(percent, 1f);
if(!isRelease){
loadingLayout.onPullHeader(Math.min(percent, 1f));
loadingLayout.onPullHeader(percent);
}

} else if (isPullFooter) {
if (y > getFooterScrollRange()) {
y = getFooterScrollRange();
Expand All @@ -260,6 +271,7 @@ public void scrollTo(@Px int x, @Px int y) {

//call percent
float percent = Math.abs(y) * 1f / footer.getMeasuredHeight();
percent = Math.min(percent, 1f);
if(!isRelease){
loadingLayout.onPullFooter(Math.min(percent, 1f));
}
Expand All @@ -271,6 +283,7 @@ public void scrollTo(@Px int x, @Px int y) {
@Override
public void computeScroll() {
super.computeScroll();
isSmoothScrolling = isRelease && Math.abs(scroller.getCurrY())>8;
if (scroller.computeScrollOffset()) {
scrollTo(scroller.getCurrX(), scroller.getCurrY());
ViewCompat.postInvalidateOnAnimation(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public void onPullHeader(float percent) {

@Override
public void onPullFooter(float percent) {
L.d("footer percent : "+percent);
tvFooterState.setText("释放立即加载");
ivFooterArrow.setRotation(360*percent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

public class L {
private static final String TAG = "XRefreshLayout";
private static boolean isDebug = true;
public static boolean isDebug = false;
public static void d(String msg){
if(isDebug){
Log.d(TAG,msg);
Expand Down

0 comments on commit 3ab8327

Please sign in to comment.