6
<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?

Satan Pandeya
  • 3,747
  • 4
  • 27
  • 53
sanket
  • 149
  • 1
  • 2
  • 11
  • I don't think you need to put RecyclerView into a NestedScrollView. It may also prevents the RecyclerView to "recycle". That should be source your problem. – Mehrzad Chehraz Jan 14 '17 at 12:55
  • if I remove the nested scroll view then the recycle view gets position in top and actually I want it like when user scrolls up the card then map fragment view gets hide and title will be displayed that's why I have used appbarlayout and I have to use nested view for that. – sanket Jan 14 '17 at 13:00
  • Try making your own LayoutManager with canScrollVertically() returning false as seen here: https://stackoverflow.com/a/41134806/2900210 – Santiago Gil Apr 04 '18 at 19:41

3 Answers3

7

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

frzdno
  • 172
  • 9
  • That's exactly what I was searching for. I haven't yet tried it but looks like a perfect one. Thanks. Upvoted – akshay bhange Aug 16 '17 at 19:09
  • 1
    Didn't work for me but using this helped. Setting on my recyclerview to disable nested scrolling with this. recyclerView.setNestedScrollingEnabled(false); – stevyhacker Aug 22 '17 at 09:26
0

<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>

0

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

sanket
  • 149
  • 1
  • 2
  • 11