简体   繁体   English

NestedScrollView smoothScroll内部的RecyclerView

[英]RecyclerView inside NestedScrollView smoothScroll

I have a recyclerView inside a NestedScrollView. 我在NestedScrollView中有一个recyclerView。 I know this is not a good practice, but I need a listener for the scroll. 我知道这不是一个好习惯,但是我需要一个侦听器来滚动。

The listener consists on notify when the user reached the final of the recyclerView. 当用户到达recyclerView的最终版本时,侦听器将包含notify。 This have a gridLayoutManager with 3 grids and the number of rows visible depends of the size of the screen. 它具有一个带有3个网格的gridLayoutManager,可见的行数取决于屏幕的大小。

Everything works but the smoothScroll. 一切正常,但smoothScroll除外。

<android.support.v4.widget.NestedScrollView
    android:id="@+id/nestedGalleryAll"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/galleryAll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</android.support.v4.widget.NestedScrollView>

This is how is working my app. 这就是我的应用程序的工作方式。

屏幕示例gif

Try this.. recylerView.setNestedScrollingEnabled(false); 试试这个recylerView.setNestedScrollingEnabled(false); in your activity.... Edit To notify user if he reached end..use this 在您的活动中...。 编辑以通知用户是否结束。

recyclerView.addOnScrollListener(new      RecyclerView.OnScrollListener() { 

   @Override
    public void onScrolled(RecyclerView recyclerView, int dx, int dy)
   {  

  LinearLayoutManager layoutManager=LinearLayoutManager.class.cast(recyclerView.getLayoutManager()); 
   int totalItemCount = layoutManager.getItemCount();

   int lastVisible = 
    layoutManager.
    findLastVisibleItemPosition();                     boolean
 endHasBeenReached 
 = lastVisible + 5 
    >= totalItemCount;
 if (totalItemCount > 0 && endHasBeenReached) 

 { //you have reached to the bottom of your recycler view } } });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM