How to disable overscroll effect on RecyclerView ONLY when you can't scroll anyway ?

前端 未结 5 1027
囚心锁ツ
囚心锁ツ 2021-02-07 00:38

Background

Sometimes, all items of the recyclerView are already visible to the user.

In this case, it wouldn\'t matter to the user to see overscroll effect, be

5条回答
  •  时光说笑
    2021-02-07 01:28

    You could try something like this:

    totalItemCount = linearLayoutManager.getItemCount();
    firstVisibleItem = linearLayoutManager.findFirstCompletelyVisibleItemPosition()
    lastVisibleItem = linearLayoutManager.findLastCompletelyVisibleItemPosition();
    
    if(firstVisibleItem == 0 && lastVisibleItem -1 == totalItemCount){
        // trigger the overscroll effect
    }
    

    Which you could add in the onScrolled() of an OnScrollListener that you add on your RecyclerView.

提交回复
热议问题