通过LinearLayoutManager获取item滑动时位置
LinearLayoutManager linearLayoutManager_content=new LinearLayoutManager(mContext, OrientationHelper.VERTICAL,false);
// RecyclerView设置滑动监听
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
int firstVisibleItemPosition=0;
switch (newState){ //判断RecyclerView滑动不同的状态
case RecyclerView.SCROLL_STATE_IDLE:
//获得当前显示在第一个item的位置
firstVisibleItemPosition = linearLayoutManager_content.findFirstVisibleItemPosition();
break;
case RecyclerView.SCROLL_STATE_DRAGGING:
//获得当前显示在第一个item的位置
firstVisibleItemPosition = linearLayoutManager_content.findFirstVisibleItemPosition();
break;
}
}
});