获取RecyclerView滑动的距离

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

如果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(); }

转载于:https://my.oschina.net/u/1177694/blog/740455

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