recyclerview怎么获取拖动的position
2016-07-19
展开全部
获取 RecyclerView 的滑动距离:
滑动到一定程度后清零是因为 getChildAt(0) 获得的是第一个可见view 用LinearLayoutManager的recyclerview测试了一下确实如此。
如果LayoutManager用的是LinearLayoutManager 可以用下面的办法,还能向下滑动多少 * * @return */ private int getDistance() { LinearLayoutManager layoutManager = (LinearLayoutManager) getLayoutManager(); View firstVisibleItem = this.getChildAt(0); int firstItemPosition = layoutManager.findFirstVisibleItemPosition(); int itemCount = layoutManager.getItemCount(); int recyclerviewHeight = this.getHeight(); int itemHeight = firstVisibleItem.getHeight(); int firstItemBottom = layoutManager.getDecoratedBottom(firstVisibleItem); return (itemCount - firstItemPosition - 1) * itemHeight - recyclerviewHeight + firstItemBottom; }
已滑动的距离:
private int getScrolledDistance() { LinearLayoutManager layoutManager = (LinearLayoutManager) getLayoutManager(); View firstVisibleItem = this.getChildAt(0); int firstItemPosition = layoutManager.findFirstVisibleItemPosition(); int itemHeight = firstVisibleItem.getHeight(); int firstItemBottom = layoutManager.getDecoratedBottom(firstVisibleItem); return (firstItemPosition + 1) * itemHeight - firstItemBottom; }
滑动到一定程度后清零是因为 getChildAt(0) 获得的是第一个可见view 用LinearLayoutManager的recyclerview测试了一下确实如此。
如果LayoutManager用的是LinearLayoutManager 可以用下面的办法,还能向下滑动多少 * * @return */ private int getDistance() { LinearLayoutManager layoutManager = (LinearLayoutManager) getLayoutManager(); View firstVisibleItem = this.getChildAt(0); int firstItemPosition = layoutManager.findFirstVisibleItemPosition(); int itemCount = layoutManager.getItemCount(); int recyclerviewHeight = this.getHeight(); int itemHeight = firstVisibleItem.getHeight(); int firstItemBottom = layoutManager.getDecoratedBottom(firstVisibleItem); return (itemCount - firstItemPosition - 1) * itemHeight - recyclerviewHeight + firstItemBottom; }
已滑动的距离:
private int getScrolledDistance() { LinearLayoutManager layoutManager = (LinearLayoutManager) getLayoutManager(); View firstVisibleItem = this.getChildAt(0); int firstItemPosition = layoutManager.findFirstVisibleItemPosition(); int itemHeight = firstVisibleItem.getHeight(); int firstItemBottom = layoutManager.getDecoratedBottom(firstVisibleItem); return (firstItemPosition + 1) * itemHeight - firstItemBottom; }
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询