获取RecyclerView滑动的距离

如果LayoutManager用的是LinearLayoutManager,强烈推荐下面的方法获取滑动距离

private int getScollYDistance() {
    LinearLayoutManager layoutManager = (LinearLayoutManager) mRecylerview.getLayoutManager();
    int position = layoutManager.findFirstVisibleItemPosition();
    View firstVisiableChildView = layoutManager.findViewByPosition(position);
    int itemHeight = firstVisiableChildView.getHeight();
    return (position) * itemHeight - firstVisiableChildView.getTop();
}

你可能感兴趣的:(获取RecyclerView滑动的距离)