1

I have three recyclerviews in a single layout file which have horizontally aligned layoutmanagers and these recyclerviews are inside nestedscrollview and I've set the nestedscrolling for each of the three recyclerviews to false too.

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/frameLayout"
    android:background="@drawable/background">

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

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

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:orientation="vertical">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="5dp"
                        android:text="FREE MOVIES"
                        android:textStyle="bold"
                        android:textSize="18sp"
                        android:textColor="@color/colorAccent"
                         />
                    <view
                        android:id="@+id/recycler_view"
                        class="android.support.v7.widget.RecyclerView"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_centerInParent="true" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:orientation="vertical">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="5dp"
                    android:text="PREMIUM MOVIES"
                    android:textColor="@color/colorAccent"
                    android:textStyle="bold"
                    android:textSize="18sp" />

                <view
                    android:id="@+id/recycler_view1"
                    class="android.support.v7.widget.RecyclerView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true" />

            </LinearLayout>


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/tvTrending"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="5dp"
                    android:text="PACKAGES"
                    android:textColor="@color/colorAccent"
                    android:textStyle="bold"
                    android:textSize="18sp" />

                <view
                    android:id="@+id/recycler_view2"
                    class="android.support.v7.widget.RecyclerView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:dividerHeight="10.0sp" />
            </LinearLayout>

        </LinearLayout>

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

    <ProgressBar
        android:id="@+id/progress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="gone"
        android:layout_gravity="center"/>

</FrameLayout>

And this is the layout of a fragment which I've called from a viewpager from MainActivity. Which has a layout like this

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.newitventure.musicnepal.MainActivity">

    <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/coordinatorLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/tabanim_appbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">


            <include
                android:id="@+id/tool_bar"
                layout="@layout/toolbar" />

            <android.support.design.widget.TabLayout
                android:id="@+id/tabLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:tabMaxWidth="0dp"
                android:background="@color/colorPrimaryDark"
                app:tabGravity="fill"
                app:tabTextAppearance="@style/MyCustomTextAppearance"
                app:tabMode="scrollable" />

        </android.support.design.widget.AppBarLayout>

        <android.support.v4.view.ViewPager
            android:id="@+id/tabanim_viewpager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="50dp"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />


    </android.support.design.widget.CoordinatorLayout>

    <LinearLayout
        android:id="@+id/gad_bottom"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_gravity="bottom"
        android:orientation="horizontal"
        android:visibility="visible">

    </LinearLayout>
</RelativeLayout>

The problem is while trying to scroll in this layout the scrolling is not smooth. It gets very laggy while trying to scroll both vertically and horizontally. What might be the issue here?

Abhinav Arora
  • 537
  • 1
  • 7
  • 23
theanilpaudel
  • 3,348
  • 8
  • 39
  • 67

2 Answers2

2

This has solved my problem:

mRecyclerView.setNestedScrollingEnabled(false);

For details :

Recyclerview inside ScrollView not scrolling smoothly

Community
  • 1
  • 1
Justcurious
  • 2,201
  • 1
  • 21
  • 36
1

Okay,

I see three possibilities from the code given

1) You're using a RelativeLayout at the root for your views. While the RelativeLayout is awesome for a lot, it does have its drawbacks. Due to how RelativeLayout is built up it measures itself twice and all children in it. So for every frame currently displayed Android needs to recalculate every view twice.

2) You do have a "rather" deep structure on your views and I think that you for example can get rid of each of the 3 linear layouts you have around the pair of TextView and recycleview.

3) You're doing something heavy in the bindView method when displaying your recyclerviews.

Now all three of these could matter and play a role in making it laggy. I would probably start with 2 (I don't think this alone will solve it completely, but it should improve the readability and speed of the code) Then I would check for 3 (If you paste your code for the Adapter I could have a look on it if there's something clear there). If that still doesn't help try 1 (which can be hard as RelativeLayout is very good for structuring code)

Hope it helps!