title: BottomNavigationView is not responding to scroll events inside Coordinator Layout
body: <p>I have an activity in which there is a <code>ViewPager</code> and the <code>BottomNavigationView</code> at the bottom of the page. The <code>ViewPager</code> consists of few fragments in it. 
  Below is the layout for the activity </p>
  
  <pre><code>&lt;LinearLayout 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:orientation="vertical"&gt;
  
      &lt;include layout="@layout/toolbar_with_tab_strip_layout" /&gt;
  
      &lt;android.support.design.widget.CoordinatorLayout
          android:id="@+id/coordinatorlayout"
          android:layout_width="match_parent"
          android:layout_height="match_parent"&gt;
  
      &lt;com.tf.eros.faythTv.widgets.NonScrollingViewPager
          android:id="@+id/home_viewpager"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_weight="1" /&gt;
  
      &lt;android.support.design.widget.BottomNavigationView
          android:id="@+id/bottom_navigation_home"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_gravity="bottom"
          android:background="@color/white"
          app:elevation="16dp"
          app:itemIconTint="@drawable/home_bottombar_icon_color_selector"
         app:itemTextColor="@drawable/home_bottombar_icon_color_selector"
          app:menu="@menu/bottom_navigation_main" /&gt;
      &lt;/android.support.design.widget.CoordinatorLayout&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>And I have also added a <code>BottomNavigationViewBehavior</code> class that will be handling the hiding/unhiding of the <code>BottomNavigationView</code> on scrolling of the fragments in the viewpager</p>
  
  <pre><code>public class BottomNavigationViewBehavior extends CoordinatorLayout.Behavior&lt;BottomNavigationView&gt; {
  
  private int height;
  
  @Override
  public boolean onLayoutChild(CoordinatorLayout parent, BottomNavigationView child, int layoutDirection) {
      height = child.getHeight();
      return super.onLayoutChild(parent, child, layoutDirection);
  }
  
  @Override
  public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, BottomNavigationView child, View directTargetChild, View target, int nestedScrollAxes) {
      return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL;
  }
  
  @Override
  public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, BottomNavigationView child, View target, int dx, int dy, int[] consumed) {
      if (dy &gt; 0) {
          slideDown(child);
      } else if (dy &lt; 0) {
          slideUp(child);
      }
  }
  
  @Override
  public void onNestedScroll(CoordinatorLayout coordinatorLayout, BottomNavigationView child, View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) {
      if (dyConsumed &gt; 0) {
          slideDown(child);
      } else if (dyConsumed &lt; 0) {
          slideUp(child);
      }
  }
  
  private void slideUp(BottomNavigationView child) {
      child.clearAnimation();
      child.animate().translationY(0).setDuration(200);
  }
  
  private void slideDown(BottomNavigationView child) {
      child.clearAnimation();
      child.animate().translationY(height).setDuration(200);
  }
  }
  </code></pre>
  
  <p>In the Activity I have added these two lines in the onCreate Method</p>
  
  <pre><code>CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) bottomNavigationView.getLayoutParams();  
  layoutParams.setBehavior(new BottomNavigationViewBehavior()); 
  </code></pre>
  
  <p>The aim is to hide the <code>BottomNavigationView</code> when the page is scrolled down(dy > 0) and make it visible when it is scrolled up (dy &lt; 0).</p>
  
  <p>Now the issue with the code is the hiding and unhiding of the <code>BottomNavigationView</code> is not spontaneous with the scrolling. Sometimes it doesn't hide at all while scrolling.                                                        </p>