android获取recycleview滚动的距离

private int getOffset() {
    LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
    int firstItemPosition = layoutManager.findFirstVisibleItemPosition();
    View firstVisibleItem = recyclerView.getChildAt(0);
    int itemWidth = firstVisibleItem.getWidth();
    int firstItemRight = layoutManager.getDecoratedRight(firstVisibleItem);
    return (recyclerView.getAdapter().getItemCount() * itemWidth
            - (firstItemPosition + 2) * itemWidth + firstItemRight);

}

返回的是recycleview的width减去滚动的距离

你可能感兴趣的:(android开发)