Skip to content

Commit e9385f1

Browse files
committed
下拉刷新
1 parent 14cd1bb commit e9385f1

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

app/src/main/java/cq/airbnb/IsChildRequestScrollListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
*/
66

77
public interface IsChildRequestScrollListener {
8-
boolean requestScroll(boolean up,boolean inTranslationMin);
8+
boolean requestScroll(boolean up,boolean shouldNotRefresh);
99
}

app/src/main/java/cq/airbnb/TabBehavior.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, View child, V
103103
}
104104

105105
//如果list需要滑动 且 不是(向上滑&&tab不在顶部)
106+
106107
if (isChildRequestScroll(child.getTranslationY())) {
107108
consumed[1] = 0;
108109
return;
@@ -213,12 +214,12 @@ public void onAnimationUpdate(ValueAnimator animation) {
213214
*/
214215
private boolean isChildRequestScroll(float translationY) {
215216
PagerAdapter adapter = mViewPager.getAdapter();
216-
boolean isTranslationMin=translationY==mTranslationMin;
217-
return ((translationY == 0 ||((translationY==mTranslationMax||isTranslationMin)&&!mUp))&&/*在顶部,或在底部且向下滑,在初始位置的时候,不给刷新,但是可以向下滑*/
217+
boolean shouldNotRefresh=translationY==mTranslationMin||translationY==0;//这两个位置的时候不应该刷新
218+
return ((translationY == 0 ||((translationY==mTranslationMax||shouldNotRefresh)&&!mUp))&&/*在顶部,或在底部且向下滑,在初始位置的时候,不给刷新,但是可以向下滑*/
218219
adapter != null && //有适配器
219220
adapter.getCount() > 0 &&//有item
220221
adapter instanceof IsChildRequestScrollListener && //实现了
221-
((IsChildRequestScrollListener) adapter).requestScroll(mUp,isTranslationMin)//需要滑动
222+
((IsChildRequestScrollListener) adapter).requestScroll(mUp,shouldNotRefresh)//需要滑动
222223
);
223224
}
224225

app/src/main/java/cq/behaviordemo/ItemFragment.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ private void initView() {
6060

6161

6262
@Override
63-
public boolean requestScroll(boolean up,boolean isTranslationMin) {
63+
public boolean requestScroll(boolean up,boolean shouldNotRefresh) {
6464
//向上滑动,并且 mRecyclerView 可以上滑动
6565
return (up && ViewCompat.canScrollVertically(mRecyclerView, 1)) ||
66-
//向下滑动,且可以下滑或者(可以刷新,且不在初始位置)
66+
//向下滑动,且可以下滑或者(可以刷新,且不在初始位置,不在顶部)
6767
(!up && (ViewCompat.canScrollVertically(mRecyclerView, -1) ||
68-
(!isTranslationMin&&((LinearLayoutManager) mRecyclerView.getLayoutManager()).findFirstCompletelyVisibleItemPosition() == 0)));
68+
(!shouldNotRefresh&&((LinearLayoutManager) mRecyclerView.getLayoutManager()).findFirstCompletelyVisibleItemPosition() == 0)));
6969

7070
}
7171

app/src/main/java/cq/behaviordemo/adapter/ItemAdapter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ public CharSequence getPageTitle(int position) {
6262

6363

6464
@Override
65-
public boolean requestScroll(boolean up,boolean isTranslationMin) {
65+
public boolean requestScroll(boolean up,boolean shouldNotRefresh) {
6666
//有子项目,有设置 vp ,没被清掉
6767
if(mViewPager!=null&&mViewPager.get()!=null ){
6868
int currentItem=mViewPager.get().getCurrentItem();
6969
//实现了接口
7070
if(getItem(currentItem) instanceof IsChildRequestScrollListener)
71-
return ((IsChildRequestScrollListener)getItem(currentItem)).requestScroll(up,isTranslationMin);
71+
return ((IsChildRequestScrollListener)getItem(currentItem)).requestScroll(up,shouldNotRefresh);
7272
}
7373

7474
return false;

0 commit comments

Comments
 (0)