请先阅读这篇文章
好多东西抄自这里
一些细节没有实现 ,见谅,录制的gif效果也不太好 :-(
Tab 监听 onNestedPreScroll来进行滑动,Toolbar 依赖 FytContent,其余的依赖 Tab
-
Tab的移动是手指滑动距离的 1/2 ,会根据停下来的位置判断是应该回到原位置还是下一个状态并进行移动 -
VP跟随Tab,HeaderScrollingViewBehavior什么的请看建议,移动则没什么难度 -
BGContent跟随Tab,根据Tab运动的比例,缩放,移动,修改 里面View的Alpha -
BG跟随Tab,首先向下移动到BGContent的高度的 1/2的地方 -
Editor跟随Tab,首先移动到BGContent下面加上预留的Padding,随着比例移动并设置alpha -
Icon跟随Tab,根据Tab运动的比例进行移动和调整大小 -
Name同上 -
Socre同上,没有缩放 -
ToolBarIcon跟随BGContent,根据BGContent移动的比例修改图标的Alpha
//TabBehavior
@Override
public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, View child, View target, int dx, int dy, int[] consumed) {
super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed);
//只要开始拦截,就需要把所有Scroll事件消费掉
consumed[1]=dy;
int distance=-dy/2;//降低移动的速度
mUp=dy>0;
if(child.getTranslationY()+distance<-mMaxDistance){
distance=-mMaxDistance;
}else if(child.getTranslationY()+distance>0){
distance=0;
}else {
distance= (int) (child.getTranslationY()+distance);
}
child.setTranslationY(distance);
}
//ListBehavior
@Override
int getScrollRange(View v) {
if (isDependOn(v)) {
return -mHeightToolbar;
} else {
return super.getScrollRange(v);
}
}
// HeaderScrollingViewBehavior$onMeasure 所以要返回 - mHeightToolbar
final int height = availableHeight - header.getMeasuredHeight()
+ getScrollRange(header);代码是蛮简单的 ,直接看项目即可,就那几行代码

