title: How to disable scrolling of NestedScrollView&CollapsingToolbarLayout, for example when there is no more content below?
body: <h2>Background</h2>
  
  <p>I try to add the same functionality as shown on many apps, where the upper area of the screen shrinks&amp;expands according to the scrolled content.</p>
  
  <p>For this, I use Google's design library, as shown on <a href="https://github.com/chrisbanes/cheesesquare" rel="noreferrer"><strong>the CheeseSquare sample</strong></a>.</p>
  
  <h2>The problem</h2>
  
  <p>Thing is, no matter how much content there is in the NestedScrollView , it lets me scroll way below the last view of the content, just to let me see the final state of the actionbar, having the minimal size of itself.</p>
  
  <p>In short, this is what I see when scrolling to the bottom (modified content of CheeseSquare sample):</p>
  
  <p><a href="https://i.stack.imgur.com/JYxsE.gif" rel="noreferrer"><img src="https://i.stack.imgur.com/JYxsE.gif" alt="enter image description here"></a></p>
  
  <p>while this is what I'd like to have when scrolling to the bottom (taken from contacts app) :</p>
  
  <p><a href="https://i.stack.imgur.com/t2qFA.gif" rel="noreferrer"><img src="https://i.stack.imgur.com/t2qFA.gif" alt="enter image description here"></a></p>
  
  <p>I'm also trying to fix a bug on <a href="https://github.com/AndroidDeveloperLB/ThreePhasesBottomSheet" rel="noreferrer"><strong>ThreePhasesBottomSheet</strong></a> sample that scrolling in the bottom sheet content is possible even when it's in peek-state. To reproduce, start scrolling horizontally (which doesn't do anything, as there is nothing to scroll this way) and then vertically, which would somehow trigger scrolling of the content of the bottom-sheet.</p>
  
  <p>Therefore, I need to disable there the scrolling in "transformView()" method, in the case that "translation
  
  <p>This is how it works using normal usage:</p>
  
  <p><a href="https://i.stack.imgur.com/fFVvm.gif" rel="noreferrer"><img src="https://i.stack.imgur.com/fFVvm.gif" alt="enter image description here"></a></p>
  
  <p>And this is how it behaves with the bug of not blocking the scrolling:</p>
  
  <p><a href="https://i.stack.imgur.com/28tZR.gif" rel="noreferrer"><img src="https://i.stack.imgur.com/28tZR.gif" alt="enter image description here"></a></p>
  
  <h2>What I've tried</h2>
  
  <p>I've tried to play with the "<a href="http://developer.android.com/reference/android/support/design/widget/AppBarLayout.LayoutParams.html#setScrollFlags(int)" rel="noreferrer"><strong>layout_scrollFlags</strong></a>" flags, to change the height to wrap_content, and to remove the clipToPadding and fitsSystemWindows attributes.</p>
  
  <p>Here's the sample XML file, which I've modified to include only a single cardView instead of many:</p>
  
  <pre><code>&lt;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/main_content"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:fitsSystemWindows="true"&gt;
  
      &lt;android.support.design.widget.AppBarLayout
          android:id="@+id/appbar"
          android:layout_width="match_parent"
          android:layout_height="@dimen/detail_backdrop_height"
          android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
          android:fitsSystemWindows="true"&gt;
  
          &lt;android.support.design.widget.CollapsingToolbarLayout
              android:id="@+id/collapsing_toolbar"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              app:layout_scrollFlags="scroll|exitUntilCollapsed"
              android:fitsSystemWindows="true"
              app:contentScrim="?attr/colorPrimary"
              app:expandedTitleMarginStart="48dp"
              app:expandedTitleMarginEnd="64dp"&gt;
  
              &lt;ImageView
                  android:id="@+id/backdrop"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:scaleType="centerCrop"
                  android:fitsSystemWindows="true"
                  app:layout_collapseMode="parallax" /&gt;
  
              &lt;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" /&gt;
  
          &lt;/android.support.design.widget.CollapsingToolbarLayout&gt;
  
      &lt;/android.support.design.widget.AppBarLayout&gt;
  
      &lt;android.support.v4.widget.NestedScrollView
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          app:layout_behavior="@string/appbar_scrolling_view_behavior"&gt;
  
          &lt;LinearLayout
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="vertical"
              android:paddingTop="24dp"&gt;
  
              &lt;android.support.v7.widget.CardView
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_margin="@dimen/card_margin"&gt;
  
                  &lt;LinearLayout
                      style="@style/Widget.CardContent"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"&gt;
  
                      &lt;TextView
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:text="Info"
                          android:textAppearance="@style/TextAppearance.AppCompat.Title" /&gt;
  
                      &lt;TextView
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:text="@string/cheese_ipsum" /&gt;
  
                  &lt;/LinearLayout&gt;
  
              &lt;/android.support.v7.widget.CardView&gt;
  
          &lt;/LinearLayout&gt;
  
      &lt;/android.support.v4.widget.NestedScrollView&gt;
  
      &lt;android.support.design.widget.FloatingActionButton
          android:layout_height="wrap_content"
          android:layout_width="wrap_content"
          app:layout_anchor="@id/appbar"
          app:layout_anchorGravity="bottom|right|end"
          android:src="@drawable/ic_discuss"
          android:layout_margin="@dimen/fab_margin"
          android:clickable="true"/&gt;
  
  &lt;/android.support.design.widget.CoordinatorLayout&gt;
  </code></pre>
  
  <p>I've tried the next code too :</p>
  
  <pre><code>((AppBarLayout.LayoutParams) collapsingToolbar.getLayoutParams()).setScrollFlags(0);
  </code></pre>
  
  <p>but this still allowed scrolling of the NestedScrollView itself in the <a href="https://github.com/chrisbanes/cheesesquare" rel="noreferrer"><strong>CheeseSquare</strong></a> example, and also allowed flinging in the <a href="https://github.com/AndroidDeveloperLB/ThreePhasesBottomSheet" rel="noreferrer"><strong>ThreePhasesBottomSheet</strong></a> sample . </p>
  
  <h2>The questions</h2>
  
  <ol>
  <li><p>What can I do in order to make the scrolling stop when there is no more content to show at the bottom?</p></li>
  <li><p>In addition, what can be done to disable scrolling of the NestedScrollView in any time I wish ( for the <a href="https://github.com/AndroidDeveloperLB/ThreePhasesBottomSheet" rel="noreferrer"><strong>ThreePhasesBottomSheet</strong></a> sample) ? Something like "setEnableScrolling(...)" ? </p>
  
  <p>I've tried to extend NestedScrollView and also extend from ScrollingViewBehavior, but failed to find what can be done to disable the scrolling.</p></li>
  </ol>
  
  <p>It's probably a very simple thing to change, but I can't find out what...</p>
  
  <p>EDIT: if needed, this is what I currently use for the design&amp;support library</p>
  
  <pre><code>compile 'com.android.support:appcompat-v7:23.1.0'
  compile 'com.android.support:design:23.1.0'
  </code></pre>
  
  <hr>
  
  <p>EDIT: for #2, I've found a workaround from within the BottomSheetLayout.java file, to disable all that's related to the variable "sheetViewOwnsTouch", as if it's always set to "false". This will allow stealing touch events on the bottom sheet. However, this is just a workaround, and only for this case. It also causes some touch events that should have been handled by other views. I still wish to know how to block the scrolling programmatically, and also in the other case of enough-space-to-show-content.</p>