提供ArgbEvaluator
//提供一个对象,用于处理颜色的渐变过程
private ArgbEvaluator argbEvaluator = new ArgbEvaluator();
recyclerview滚动监听
rvHome.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
//滚动状态发生改变的时候调用的方法
super.onScrollStateChanged(recyclerView, newState);
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
sumY += dy;
int bgColor = 0X553190E8;
if (sumY == 0) {
//开始色值
bgColor = 0X553190E8;
} else if (sumY >= 300) {
//最终色值
bgColor = 0XFF3190E8;
} else {
//渐变色值,伴随手指移动,移动的越多颜色变化的就越多
bgColor = (int) argbEvaluator.evaluate(sumY / 300.0f, 0X553190E8, 0XFF3190E8);
}
llTitleContainer.setBackgroundColor(bgColor);
super.onScrolled(recyclerView, dx, dy);
}
});
super.onActivityCreated(savedInstanceState);
}