Pagination not work for the RecyclerView within NestedScrollView

前端 未结 3 1508
时光说笑
时光说笑 2020-11-28 09:58

How to implement pagination of recyclerview that is within NestedScrollView?

3条回答
  •  时光说笑
    2020-11-28 10:37

    if you are using Kotlin your code will be looks like

     scroll?.viewTreeObserver?.addOnScrollChangedListener {
            val view = scroll.getChildAt(scroll.childCount - 1)
            Timber.d("Count==============${scroll.childCount}")
    
            val diff = view.bottom - (scroll.height + scroll.scrollY)
            Timber.d("diff==============$diff")
    
            if (diff == 0) {
                //your api call to fetch data
            }
        }
    

    and last but the not the least set RecyclerView scrolling false

     ViewCompat.setNestedScrollingEnabled(recyclerView, false)
    

提交回复
热议问题