2

I'm using CoordinatorLayout with CollapsingToolBar and NestedScrollView. The elements are being inserted via RecyclerView. Whenever I try to scroll up or down the scroll isn't smooth, it's very slow, regardless the velocity of the gesture. I tried the solution here but it didn't solve my problem. So I have no idea what causes this problem or how to solve it.

Here is my xml layout

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    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"
    android:id="@+id/main_screen_frame">

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

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsingToolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|enterAlways"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginStart="48dp"
            app:expandedTitleMarginEnd="64dp">

            <ImageView
                android:id="@+id/toolbarImage"
                android:layout_width="150dp"
                android:layout_height="100dp"
                android:scaleType="centerCrop"
                android:src="@drawable/logo"
                android:layout_gravity="center"
                app:layout_scrollFlags="scroll|enterAlways"
                app:layout_collapseMode="parallax"/>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:layout_collapseMode="pin"
                android:layout_gravity="bottom"
                app:layout_scrollFlags="scroll|enterAlways">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">

                    <android.support.v7.widget.SearchView
                        android:id="@+id/search_view_id"
                        android:layoutDirection="rtl"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:queryHint="@string/search_view_hint"
                        android:queryBackground="@color/colorWhite"
                        android:layout_gravity="right"/>

                </LinearLayout>

            </android.support.v7.widget.Toolbar>

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

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

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">


        <LinearLayout
                android:id="@+id/search_panel_id"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:layoutDirection="rtl">

                <TextView
                    android:id="@+id/text_view_id"
                    android:layout_width="200dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:textAlignment="center"
                    android:text="@string/secondary_title"
                    android:layout_marginBottom="5dp"/>

            </LinearLayout>

            <FrameLayout
                android:id="@+id/fragment_layout_id"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/search_panel_id"
                android:layout_marginTop="10dp"
                android:orientation="horizontal">

            </FrameLayout>

        </RelativeLayout>

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

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

The FrameLayout is a place holder for different fragments with different scrollable RecyclerViews. Thanks in advance.

Bertram Gilfoyle
  • 9,899
  • 6
  • 42
  • 67
Keselme
  • 3,779
  • 7
  • 36
  • 68

3 Answers3

0

Layout structure seems okay. So the problem might be here. android:src="@drawable/logo".

Try moving it to drawable-nodpi directory. Also loading with Picasso / Glide will improve perfomance.

Bertram Gilfoyle
  • 9,899
  • 6
  • 42
  • 67
0

Solved my problem with this solution. The problem was that I was using RecycleView, that came from an injected fragment, inside of NestedScrollVoew. I guess they both contradict each other so that caused the slow scrolling.

Keselme
  • 3,779
  • 7
  • 36
  • 68
0

recyclerViewsetNestedScrollingEnabled(false);

The above line makes recyclerview scrolling smoother in a NestedScrollView.

Shambhu
  • 181
  • 6
  • 16