Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use RecyclerView inside NestedScrollView

I have this layout:

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

    <LinearLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

            <--There is some layouts here-->
            <RecyclerView
                android:id="@+id/recycler_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>
    </LinearLayout>

</android.support.v4.widget.NestedScrollView>

It works well. I can scroll RecyclerView smoothly without scrolling parent view.

Now I have to put the RecyclerView inside a FrameLayout like this:

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

    <LinearLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
 <--There is some layouts here-->
        <FrameLayout
            android:id="@+id/review_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <RecyclerView
                android:id="@+id/recycler_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>

            <include
                android:id="@+id/empty_view"
                layout="@layout/review_empty_view"
                android:visibility="gone" />
        </FrameLayout>
    </LinearLayout>

</android.support.v4.widget.NestedScrollView>

Now I cannot scroll the RecyclerView smoothly. All I want is: scroll RecyclerView smoothly without scrolling parent view. What should I do?

EDIT: Here is my review_empty layout:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="horizontal"
    android:padding="16dp">

    <ImageView
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:src="@drawable/shopping_review_empty" />

    <android.support.v4.widget.Space
        android:layout_width="32dp"
        android:layout_height="0dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/shopping_no_review_message" />
</LinearLayout>
like image 653
TOP Avatar asked Jun 09 '17 09:06

TOP


2 Answers

just enable nestedscrolling that will enable smooth scrollview.

RecyclerView v = (RecyclerView) findViewById(...);
v.setNestedScrollingEnabled(false);
like image 118
jai khambhayta Avatar answered Oct 06 '22 07:10

jai khambhayta


Use this in your recyclerView

app:layout_behavior="@string/appbar_scrolling_view_behavior"
like image 27
Randhir Gupta Avatar answered Oct 06 '22 08:10

Randhir Gupta