|
58 | 58 | //TabBehavior |
59 | 59 | public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, View child, View target, int dx, int dy, int[] consumed) { |
60 | 60 | 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;//降低移动的速度 |
69 | 61 | 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); |
79 | 78 | } |
80 | 79 |
|
81 | 80 | /** |
82 | 81 | * Child是否需要滑动 |
83 | 82 | */ |
84 | 83 | 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 | + ); |
91 | 90 | } |
92 | 91 |
|
93 | 92 |
|
94 | 93 | //设置 listener 检测是否需要展开 |
95 | 94 | @Override |
96 | 95 | 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; |
106 | 105 | } |
107 | 106 |
|
108 | 107 | /** |
109 | 108 | * list fling到头的时候 展开 |
110 | 109 | */ |
111 | 110 | @Override |
112 | 111 | 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 | + } |
123 | 123 | } |
124 | 124 |
|
125 | 125 | /** |
|
0 commit comments