如何监听到RecyclerView中列表项Item的滑动手势
1个回答
展开全部
获取 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; }
七鑫易维信息技术
2024-09-02 广告
2024-09-02 广告
Play Video 七鑫易维是致力于机器视觉和人工智能领域的高新科技企业,迄今已专注眼球追踪技术的研发、创新与应用超过14年,拥有完全自主知识产权,全球专利总量655余项。 作为眼球追踪技术领域的全球知名品牌,七鑫易维的产品体系覆盖眼动分...
点击进入详情页
本回答由七鑫易维信息技术提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询