sanket
sanket

Reputation: 149

how to do smooth scrolling with nested scroll view inside coordinator layout

<android.support.design.widget.CoordinatorLayout 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:background="@android:color/background_light"
    android:fitsSystemWindows="true">

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

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/main_collapsing"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleTextAppearance="@android:color/transparent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:title="">

            <fragment xmlns:tools="http://schemas.android.com/tools"
                android:id="@+id/map"
                android:name="com.google.android.gms.maps.SupportMapFragment"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                tools:context="com.mydermacy.www.beyou.activities.CompareClinicsActivity" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/main_toolbar_clinics"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

        </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"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">


    <android.support.v7.widget.RecyclerView
            android:id="@+id/rc_clinic_compare"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:behavior_overlapTop="184dp"
            android:background="@color/background" />

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

    <!--app:layout_behavior="@string/appbar_scrolling_view_behavior" />-->

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

I have layout with CoordinatorLayout as a rootview and inside that I have two child view AppBarLayout and NestedScrollView. I am not able to do smooth scrolling. What can be done to achieve smooth scrolling?

Upvotes: 6

Views: 12606

Answers (3)

sanket
sanket

Reputation: 149

i removed the nested scroll view and app:behavior_overlapTop="184dp" from recycle view so the problem got solved also i added app:layout_behavior="@string/appbar_scrolling_view_behavior" to recycle view thanks for help

Upvotes: 0

Anuj Kamboj
Anuj Kamboj

Reputation: 13

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="match_parent">

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

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/main_collapsing"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:expandedTitleTextAppearance="@android:color/transparent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:title="">

        <fragment xmlns:tools="http://schemas.android.com/tools"
            android:id="@+id/map"
            android:name="com.google.android.gms.maps.SupportMapFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context="com.mydermacy.www.beyou.activities.CompareClinicsActivity" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/main_toolbar_clinics"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

    </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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">


    <android.support.v7.widget.RecyclerView
        android:id="@+id/rc_clinic_compare"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:behavior_overlapTop="184dp"
        android:background="@color/background" />

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

<!--app:layout_behavior="@string/appbar_scrolling_view_behavior" />-->
</RelativeLayout>
</ScrollView>

Upvotes: 0

frzdno
frzdno

Reputation: 172

CoordinatorLayout and CollapsingToolbarLayout smooth scroll is bug and Google still has not fixed it. :|

remove NestedScrollView. RecyclerView with app:layout_behavior="@string/appbar_scrolling_view_behavior" That's enough and fix.

you can use third party library : smooth-app-bar-layout

Upvotes: 7

Related Questions