如何监听到RecyclerView中列表项Item的滑动手势
答案:2 悬赏:40 手机版
解决时间 2021-04-09 04:45
- 提问者网友:酱爆肉
- 2021-04-08 06:10
如何监听到RecyclerView中列表项Item的滑动手势
最佳答案
- 五星知识达人网友:未来江山和你
- 2021-04-08 07:31
获取 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; }
全部回答
- 1楼网友:往事埋风中
- 2021-04-08 08:28
虽然我很聪明,但这么说真的难到我了
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯