当您仍然无法滚动时,如何仅在RecyclerView上禁用过度滚动效果? [英] How to disable overscroll effect on RecyclerView ONLY when you can't scroll anyway ?

查看:601
本文介绍了当您仍然无法滚动时,如何仅在RecyclerView上禁用过度滚动效果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时候,用户已经可以看到recyclerView的所有项目.

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, because it's impossible to actually scroll and see more items.

我知道,要在RecyclerView上禁用过度滚动效果,我可以使用:

I know that in order to disable overscroll effect on RecyclerView, I can just use:

recyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);

但是当无法滚动时,我无法确定何时触发此操作.

but I can't find out when to trigger this, when the scrolling isn't possible anyway.

如何确定所有项目都是完全可见的,并且用户不能真正滚动?

How can I Identify that all items are fully visible and that the user can't really scroll ?

如果有助于假设任何事情,那么我始终对RecyclerView使用LinearLayoutManager(垂直和水平).

If it helps to assume anything, I always use LinearLayoutManager (vertical and horizontal) for the RecyclerView.

推荐答案

,您可以尝试OVER_SCROLL_IF_CONTENT_SCROLLS.根据文档

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);
}

这篇关于当您仍然无法滚动时,如何仅在RecyclerView上禁用过度滚动效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆