(没有占满也算滑动到底部,记录这条是为了满足一些特殊的需求,如果是其他的,也可以尝试这个,上代码)
private val onScrollListener = object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView : RecyclerView , dx : Int , dy : Int) {
super.onScrolled(recyclerView , dx , dy)
val layoutManager = recyclerView.layoutManager as LinearLayoutManager
//得到当前显示的最后一个item的view
val lastChildView = layoutManager.getChildAt(layoutManager.childCount - 1)
lastChildView?.let {
//得到lastChildView的bottom坐标值
val lastChildBottom = lastChildView.bottom
//得到Recyclerview的底部坐标减去底部padding值,也就是显示内容最底部的坐标
val recyclerBottom = recyclerView.bottom - recyclerView.paddingBottom
//判断lastChildView的bottom值跟recyclerBottom
//如果满足则说明是真正的滑动到了底部
if (lastChildBottom <= recyclerBottom ) {
bt_red_withdraw.visibility = View.VISIBLE
}
}
}
}
网友评论