Skip to content

Commit 045e327

Browse files
author
scwang90
committed
完成 1.0.2 版本
1 parent 4144428 commit 045e327

2 files changed

Lines changed: 52 additions & 5 deletions

File tree

app/src/main/res/layout/activity_practice_feedlist.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
</RelativeLayout>
130130
</FrameLayout>
131131

132-
<ScrollView
132+
<android.support.v4.widget.NestedScrollView
133133
android:layout_width="match_parent"
134134
android:layout_height="match_parent"
135135
android:paddingTop="130dp"
@@ -945,7 +945,7 @@
945945
</com.flyco.roundview.RoundLinearLayout>
946946
</LinearLayout>
947947
</LinearLayout>
948-
</ScrollView>
948+
</android.support.v4.widget.NestedScrollView>
949949

950950
</FrameLayout>
951951

refresh-layout/src/main/java/com/scwang/smartrefresh/layout/impl/RefreshContentWrapper.java

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import android.support.v4.view.PagerAdapterWrapper;
1818
import android.support.v4.view.ScrollingView;
1919
import android.support.v4.view.ViewPager;
20+
import android.support.v4.widget.NestedScrollView;
2021
import android.support.v4.widget.Space;
2122
import android.support.v7.widget.LinearLayoutManager;
2223
import android.support.v7.widget.RecyclerView;
@@ -303,6 +304,9 @@ public void setupComponent(RefreshKernel kernel, View fixedHeader, View fixedFoo
303304
if (mScrollableView instanceof AbsListView) {
304305
AbsListViewScrollComponent component = new AbsListViewScrollComponent(kernel);
305306
component.attach(((AbsListView) mScrollableView));
307+
} else if (mScrollableView instanceof NestedScrollView) {
308+
NestedScrollViewScrollComponent component = new NestedScrollViewScrollComponent(kernel);
309+
component.attach((NestedScrollView) mScrollableView);
306310
} else if (Build.VERSION.SDK_INT >= 23 && mScrollableView != null) {
307311
mScrollableView.setOnScrollChangeListener(new Api23ViewScrollComponent(kernel));
308312
}
@@ -434,7 +438,7 @@ public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int
434438
// System.out.println("ValueAnimator - " + (lastTime - lastTimeOld) + " - " + velocity+"("+(lastOldScrollY - oldScrollY)+")");
435439
kernel.animSpinnerBounce(Math.min(velocity, mHeaderHeight));
436440
} else if (oldScrollY < scrollY && mMotionEvent == null && overScroll && layout.isEnableLoadmore()) {
437-
if (lastTime - lastTimeOld > 1000 && !ScrollBoundaryUtil.canScrollDown(mScrollableView)) {
441+
if (lastTime - lastTimeOld > 1000 && !ScrollBoundaryUtil.canScrollDown(v)) {
438442
final int velocity = (lastOldScrollY - oldScrollY) * 16000 / (int)((lastTime - lastTimeOld)/1000f);
439443
// System.out.println("ValueAnimator - " + (lastTime - lastTimeOld) + " - " + velocity+"("+(lastOldScrollY - oldScrollY)+")");
440444
kernel.animSpinnerBounce(Math.max(velocity, -mFooterHeight));
@@ -447,6 +451,48 @@ public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int
447451
}
448452
}
449453

454+
private class NestedScrollViewScrollComponent implements NestedScrollView.OnScrollChangeListener {
455+
long lastTime = 0;
456+
long lastTimeOld = 0;
457+
int lastScrollY = 0;
458+
int lastOldScrollY = 0;
459+
RefreshKernel kernel;
460+
461+
NestedScrollViewScrollComponent(RefreshKernel kernel) {
462+
this.kernel = kernel;
463+
}
464+
465+
@Override
466+
public void onScrollChange(NestedScrollView scrollView, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
467+
if (lastScrollY == scrollY && lastOldScrollY == oldScrollY) {
468+
return;
469+
}
470+
RefreshLayout layout = kernel.getRefreshLayout();
471+
boolean overScroll = layout.isEnableOverScrollBounce() || layout.isRefreshing() || layout.isLoading();
472+
if (scrollY <= 0 && oldScrollY > 0 && mMotionEvent == null && lastTime - lastTimeOld > 1000 && overScroll && layout.isEnableRefresh()) {
473+
final int velocity = (lastOldScrollY - oldScrollY) * 16000 / (int)((lastTime - lastTimeOld)/1000f);
474+
kernel.animSpinnerBounce(Math.min(velocity, mHeaderHeight));
475+
} else if (oldScrollY < scrollY && mMotionEvent == null && layout.isEnableLoadmore()) {
476+
if (!layout.isLoadmoreFinished() && layout.isEnableAutoLoadmore()
477+
&& layout.getState() == RefreshState.None
478+
&& !ScrollBoundaryUtil.canScrollDown(scrollView)) {
479+
kernel.getRefreshLayout().autoLoadmore(0, 1);
480+
} else if (overScroll && lastTime - lastTimeOld > 1000 && !ScrollBoundaryUtil.canScrollDown(mScrollableView)) {
481+
final int velocity = (lastOldScrollY - oldScrollY) * 16000 / (int)((lastTime - lastTimeOld)/1000f);
482+
kernel.animSpinnerBounce(Math.max(velocity, -mFooterHeight));
483+
}
484+
}
485+
lastScrollY = scrollY;
486+
lastOldScrollY = oldScrollY;
487+
lastTimeOld = lastTime;
488+
lastTime = System.nanoTime();
489+
}
490+
491+
void attach(NestedScrollView scrollView) {
492+
scrollView.setOnScrollChangeListener(this);
493+
}
494+
}
495+
450496
private class AbsListViewScrollComponent implements AbsListView.OnScrollListener {
451497

452498
int scrollY;
@@ -483,8 +529,9 @@ public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleI
483529
}
484530
} else if (dy < 0) {
485531
int lastVisiblePosition = absListView.getLastVisiblePosition();
486-
if (lastVisiblePosition == totalItemCount - 1 && lastVisiblePosition > 0) {
487-
if (layout.isEnableLoadmore() && !layout.isLoadmoreFinished() && layout.isEnableAutoLoadmore()
532+
if (lastVisiblePosition == totalItemCount - 1 && lastVisiblePosition > 0
533+
&& layout.isEnableLoadmore()) {
534+
if (!layout.isLoadmoreFinished() && layout.isEnableAutoLoadmore()
488535
&& layout.getState() == RefreshState.None
489536
&& !ScrollBoundaryUtil.canScrollDown(absListView)) {
490537
kernel.getRefreshLayout().autoLoadmore(0, 1);

0 commit comments

Comments
 (0)