直接上代码吧,应该你们也看得懂。
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定义在类变量即可
网友评论