Skip to content

Commit d13d416

Browse files
author
csnowstack
committed
read me ..
1 parent 6897af2 commit d13d416

File tree

1 file changed

+42
-42
lines changed

1 file changed

+42
-42
lines changed

README.md

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -58,68 +58,68 @@
5858
//TabBehavior
5959
public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, View child, View target, int dx, int dy, int[] consumed) {
6060
super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed);
61-
62-
if(isChildRequestScroll(child.getTranslationY())){//如果list需要滑动这边就不动
63-
consumed[1]=0;
64-
return;
65-
}
66-
67-
consumed[1]=dy;//全部消耗
68-
int distance = -dy / 2;//降低移动的速度
6961
mUp = dy > 0;
70-
71-
if (child.getTranslationY() + distance < -mMaxDistance) {
72-
distance = -mMaxDistance;
73-
} else if (child.getTranslationY() + distance > 0) {
74-
distance = 0;
75-
} else {
76-
distance = (int) (child.getTranslationY() + distance);
77-
}
78-
child.setTranslationY(distance);
62+
if(isChildRequestScroll(child.getTranslationY())){//如果list需要滑动这边就不动
63+
consumed[1]=0;
64+
return;
65+
}
66+
consumed[1]=dy;//全部消耗
67+
int distance = -dy / 2;//降低移动的速度
68+
69+
70+
if (child.getTranslationY() + distance < -mMaxDistance) {
71+
distance = -mMaxDistance;
72+
} else if (child.getTranslationY() + distance > 0) {
73+
distance = 0;
74+
} else {
75+
distance = (int) (child.getTranslationY() + distance);
76+
}
77+
child.setTranslationY(distance);
7978
}
8079

8180
/**
8281
* Child是否需要滑动
8382
*/
8483
private boolean isChildRequestScroll(float translationY) {
85-
return (translationY == -mMaxDistance &&//在顶部
86-
mViewPager.getAdapter() != null && //有适配器
87-
mViewPager.getAdapter().getCount() > 0 &&//有item
88-
mViewPager.getAdapter() instanceof IsChildRequestScrollListener && //实现了
89-
((IsChildRequestScrollListener) mViewPager.getAdapter()).requestScroll()//需要滑动
90-
);
84+
return (translationY == -mMaxDistance &&//在顶部
85+
mViewPager.getAdapter() != null && //有适配器
86+
mViewPager.getAdapter().getCount() > 0 &&//有item
87+
mViewPager.getAdapter() instanceof IsChildRequestScrollListener && //实现了
88+
((IsChildRequestScrollListener) mViewPager.getAdapter()).requestScroll(mUp)//需要滑动
89+
);
9190
}
9291

9392

9493
//设置 listener 检测是否需要展开
9594
@Override
9695
public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, View child, View directTargetChild, View target, int nestedScrollAxes) {
97-
mControlChange=true;
98-
99-
if(mViewPager.getAdapter() != null && //有适配器
100-
mViewPager.getAdapter().getCount() > 0 &&//有item
101-
mViewPager.getAdapter() instanceof SupportNeedExpendListener&&
102-
((SupportNeedExpendListener) mViewPager.getAdapter()).getNeedExpendListener()==null){
103-
((SupportNeedExpendListener) mViewPager.getAdapter()).setNeedExpendListener(this);
104-
}
105-
return (nestedScrollAxes & ViewCompat.SCROLL_AXIS_VERTICAL) != 0;
96+
mControlChange=true;
97+
98+
if(mViewPager.getAdapter() != null && //有适配器
99+
mViewPager.getAdapter().getCount() > 0 &&//有item
100+
mViewPager.getAdapter() instanceof SupportNeedExpendListener&&
101+
((SupportNeedExpendListener) mViewPager.getAdapter()).getNeedExpendListener()==null){
102+
((SupportNeedExpendListener) mViewPager.getAdapter()).setNeedExpendListener(this);
103+
}
104+
return (nestedScrollAxes & ViewCompat.SCROLL_AXIS_VERTICAL) != 0;
106105
}
107106

108107
/**
109108
* list fling到头的时候 展开
110109
*/
111110
@Override
112111
public void needExpand() {
113-
if(!mControlChange){//如果是手指在控制就不管
114-
mValueAnimator.setDuration(500);
115-
mValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
116-
@Override
117-
public void onAnimationUpdate(ValueAnimator animation) {
118-
mTab.setTranslationY((animation.getAnimatedFraction()-1)*mMaxDistance);
119-
}
120-
});
121-
mValueAnimator.start();
122-
}
112+
if(!mControlChange){
113+
mValueAnimator.setDuration(500);
114+
mValueAnimator.removeAllUpdateListeners();
115+
mValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
116+
@Override
117+
public void onAnimationUpdate(ValueAnimator animation) {
118+
mTab.setTranslationY((animation.getAnimatedFraction()-1)*mMaxDistance);
119+
}
120+
});
121+
mValueAnimator.start();
122+
}
123123
}
124124

125125
/**

0 commit comments

Comments
 (0)