How to use RecyclerView inside NestedScrollView?

前端 未结 24 2432
抹茶落季
抹茶落季 2020-11-22 03:39

How to use RecyclerView inside NestedScrollView? RecyclerView content is not visible after setting adapter.

UPDATE

相关标签:
24条回答
  • 2020-11-22 04:38

    If you are using RecyclerView ScrollListener inside NestedScrollView, addOnScrollListener listener not working properly if you are used both.

    Use this code.

    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState); 
                  ......
            }
        });
    

    this code working fine RecyclerView ScrollListener inside NestedScrollView.

    thanks

    0 讨论(0)
  • 2020-11-22 04:41

    I have Viewpager and RecyclerView inside the NestedScrollView. After adding below lines

    recyclerView.setNestedScrollingEnabled(false);
    recyclerView.setHasFixedSize(false);
    

    I solved slow scroll and scroll lag issue.

    0 讨论(0)
  • 2020-11-22 04:41
    nestedScrollView.setNestedScrollingEnabled(true);
    
    mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                //...
            }
        });
    
    
    <androidx.core.widget.NestedScrollView
        android:id="@+id/nested"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:layout_below="@id/appBarLayout_orders"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"> 
    
        <androidx.constraintlayout.widget.ConstraintLayout ...
    
            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/recycler"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"/>
    
    0 讨论(0)
  • 2020-11-22 04:42

    Replace your recyclerView with,

    <android.support.v7.widget.RecyclerView
        android:id="@+id/conversation"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    

    here,

    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    

    will manage the rest of things.

    One more thing, no need to put your recyclerView inside NestedScrollView

    0 讨论(0)
  • 2020-11-22 04:42

    One solution to keep the recycling feature of the recyclerview and avoiding the recyclerview to load all your data is setting a fix height in the recyclerview itself. By doing this the recyclerview is limited only to load as much as its height can show the user thus recycling its element if ever you scroll to the bottom/top.

    0 讨论(0)
  • 2020-11-22 04:42

    if you want to use RecyclerView in NestedScrollView this is a simple tricky, just set :

    RecyclerView

    • recyclerView.setHasFixedSize(false) (java/kt)

    • android:nestedScrollingEnabled="false"

    • android:layout_height="wrap_content"

    • android:overScrollMode="never"

    NestedScrollView

    • android:fillViewport="true"

    this is work for me, and you can use many RecyclerView in NestedScrollView with this too.

    0 讨论(0)
提交回复
热议问题