作者:mobiledu2502923573 | 来源:互联网 | 2023-05-17 18:24
XRecyclerView的滑动,,判断向上滑动的距离是否大于600,,true灰色,,false透明,,#00000000shouXRecyclerView.setOnScrol
//XRecyclerView的滑动,,判断向上滑动的距离是否大于600,,true=灰色,,false=透明,,#00000000 shouXRecyclerView.setOnScrollChangeListener(new View.OnScrollChangeListener() {
@Override
public void onScrollChange(View view, int i, int i1, int i2, int i3) {
//获取滑动距离,,通过布局管理器 //1.获得视图的第一条木的下标 //2.根据下标获得view条目,,,在获得条目的高度 //3.下标*条目高度-可见视图距离顶部的高度 LinearLayoutManager layoutManager = (LinearLayoutManager) shouXRecyclerView.getLayoutManager();
int position = layoutManager.findFirstVisibleItemPosition();
View firstVisiableChildView = layoutManager.findViewByPosition(position);
int itemHeight = firstVisiableChildView.getHeight();
int i4 = (position) * itemHeight - firstVisiableChildView.getTop();
Log.i("jibbb","==="+i4);
if(i4>600){
sousuo.setBackgroundColor(getResources().getColor(R.color.fenleilvbeijing));
}else{
sousuo.setBackgroundColor(getResources().getColor(R.color.touming));
}
}
});