How to know whether a RecyclerView / LinearLayoutManager is scrolled to top or bottom?

后端 未结 11 2097
一向
一向 2020-12-02 06:24

Currently I am using the follow code to check whether SwipeRefreshLayout should be enabled.

private void laySwipeToggle() {
    if (mRecyclerView.getChildCou         


        
11条回答
  •  时光说笑
    2020-12-02 06:54

    To find out if the RecyclerView is scrolled to bottom, you could reuse the methods used for the scrollbar.

    This is the calculation, for convenience written as a Kotlin extension function:

    fun RecyclerView.isScrolledToBottom(): Boolean {
        val contentHeight = height - (paddingTop + paddingBottom)
        return computeVerticalScrollRange() == computeVerticalScrollOffset() + contentHeight
    }
    

提交回复
热议问题