【问题标题】:Disable overscroll effect at the bottom on RecyclerView在 RecyclerView 的底部禁用过度滚动效果
【发布时间】:2020-10-07 12:06:07
【问题描述】:

在我的程序中,底部滚动效果看起来很糟糕,所以我只想在顶部显示过度滚动效果。

这是包含 recyclerview 的 xml 文件。

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipToPadding="false"
    android:clipChildren="false">
    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/day_events_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />
</RelativeLayout>

当我设置属性android:overScrollMode="never" 时,顶部和底部滚动效果都没有显示。 谁能解决这个问题?

【问题讨论】:

标签: android


【解决方案1】:

你可以像这样使用监听器:

myRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
    @Override
    public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
        super.onScrolled(recyclerView, dx, dy);

        if (dy > 0) {

            int pos = linearLayoutManager.findLastVisibleItemPosition();
            int numItems = myRecyclerView.getAdapter().getItemCount();

            if (pos >= numItems - 1 ) {
                recyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);
            }else{
                 recyclerView.setOverScrollMode(View.OVER_SCROLL_ALWAYS); 
              }
        }
    }
});

【讨论】:

  • 感谢您的回答,但我只想阻止底部滚动,而不是检测。
  • 检测到底部过度滚动,您可以使用recyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);阻止它,并在您不在底部时重新启用
  • 啊,好的。那你可以分享完整的代码吗?目前,您的回答解释不够充分,无法被接受。
猜你喜欢
  • 1970-01-01
  • 2017-05-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多