title: Fling smoothly AppBarLayout with NestedScrollView using AppBarLayout.Behavior
body: <p>I have an AppBarLayout and NestedScrollView. I want the NestedScrollView whenever it scroll down, the AppBarLayout should also expand gracefully, without the NestedScrollView stop right before the AppBarLayout Expand; a second Flight/Scroll is required to get that done. </p>
  
  <p>I check stackoverflow and found this solution pretty related, and could be used. But instead if NestedScrollView, it is RecyclerView. It is in <a href="https://stackoverflow.com/a/32454407/3286489">https://stackoverflow.com/a/32454407/3286489</a></p>
  
  <p>I basically take the code and changed it slightly, and used to check the velocity >8000 to consider also Fling the AppBarLayout as code below.</p>
  
  <pre><code>public final class FlingBehavior extends AppBarLayout.Behavior {
      private boolean isPositive;
  
      public FlingBehavior() {
      }
  
      public FlingBehavior(Context context, AttributeSet attrs) {
          super(context, attrs);
      }
  
      @Override
      public boolean onNestedFling(CoordinatorLayout coordinatorLayout, AppBarLayout child, View target, float velocityX, float velocityY, boolean consumed) {
          if (velocityY &gt; 0 &amp;&amp; !isPositive || velocityY &lt; 0 &amp;&amp; isPositive) {
              velocityY = velocityY * -1;
          }
  
          if (target instanceof NestedScrollView &amp;&amp; Math.abs(velocityY) &gt; 8000) {
              consumed = false;
          }
          return super.onNestedFling(coordinatorLayout, child, target, velocityX, velocityY, consumed);
      }
  
      @Override
      public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, AppBarLayout child, View target, int dx, int dy, int[] consumed) {
          super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed);
          isPositive = dy &gt; 0;
      }
  }
  </code></pre>
  
  <p>This works, but not ideal. I'm only want to start (continue) the Fling on the AppBarLayout (i.e. return <code>consumed = false</code>), when the NestedScrollView has reach the top of it's scroll. How could I check that in onNestedFling?</p>
  
  <p>Thanks.</p>