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

前端 未结 5 1041
囚心锁ツ
囚心锁ツ 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:24

    you could give OVER_SCROLL_IF_CONTENT_SCROLLS a try. Accordingly to the documentation

    Allow a user to over-scroll this view only if the content is large enough to meaningfully scroll, provided it is a view that can scroll.

    Or you could check if you have enough items to trigger the scroll and enable/disable the over scroll mode, depending on it. Eg

    boolean notAllVisible = layoutManager.findLastCompletelyVisibleItemPosition() < adapter.getItemCount() - 1;
    if (notAllVisible) {
       recyclerView.setOverScrollMode(allVisible ? View.OVER_SCROLL_NEVER);
    }
    

提交回复
热议问题