Android开发recyclerView监听滑动距离,超过多少
2022-07-18 本文已影响0人
你的益达233
直接上代码吧,应该你们也看得懂。
val scrollDistance = CUtils.getScreenHeightPx(mContext)/2
mBinding.srrvDatas.recyclerView.addOnScrollListener(object :RecyclerView.OnScrollListener(){
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
super.onScrollStateChanged(recyclerView, newState)
}
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
// dy > 0 时为向上滚动
// dy < 0 时为向下滚动
scrollY += dy
LogUtils.i("onScrolled","onScrolled")
dealBaiduMatchTip(scrollY >= scrollDistance && MyApplication.currentUserInfo?.baiduMatchState != 1)
}
})
dealBaiduMatchTip方法参数就是个布尔值show。代码中scrollY定义在类变量即可