CollapsingToolbarLayout doesn’t recognize scroll fling

I had exactly the same issue with CollapsingToolbarLayout with ImageView inside and NestedScrollView. The fling scroll stops when finger is released.

However, I’ve noticed something strange. If you start scrolling with your finger from a view with OnClickListener (e.g. Button), the fling scrolling works perfectly.

Thus I fixed it with a weird solution. Set OnClickListener (that does nothing) on the direct child of NestedScrollView. Then it works perfectly!

<android.support.v4.widget.NestedScrollView 
   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"
   app:layout_behavior="@string/appbar_scrolling_view_behavior">

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

    <!-- Page Content -->

  </LinearLayout>

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

Give the direct child (LinearLayout) an id and set OnClickListener in Activity

ViewGroup mContentContainer = (ViewGroup) findViewById(R.id.content_container);    
mContentContainer.setOnClickListener(this);

@Override
public void onClick(View view) {
    int viewId = view.getId();
}

Notes:

Tested using Support Design Library 25.0.1

CollapsingToolbarLayout with scrollFlags="scroll|enterAlwaysCollapsed"

Leave a Comment