@Override
 public boolean onDependentViewChanged(
     CoordinatorLayout parent, FloatingActionButton fab, View dependency) {
   if (dependency instanceof AppBarLayout) {
     AppBarLayout appBarLayout = (AppBarLayout) dependency;
     CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
     int bottomMargin = lp.bottomMargin;
     int distanceToScroll = fab.getHeight() + bottomMargin;
     //            Log.e("@@!!", ViewCompat.getY(appBarLayout) + "\t" +
     // appBarLayout.getTotalScrollRange());
     float ratio = ViewCompat.getY(appBarLayout) / (float) appBarLayout.getTotalScrollRange();
     if (ratio < -0.9f) {
       ratio = -1f;
     }
     ViewCompat.setTranslationY(fab, -distanceToScroll * ratio);
     return true;
   }
   return false;
 }
 private float centerY(View view) {
   return ViewCompat.getY(view) + view.getHeight() / 2f;
 }
  public void update(RecyclerView referenceList, float dx, float dy) {
    if (indexList != null && indexList.getChildCount() > 2) {
      show();
      updatePosBasedOnReferenceList(referenceList);

      View firstVisibleView = indexList.getChildAt(0);
      View secondVisibleView = indexList.getChildAt(1);

      TextView firstRowIndex = (TextView) firstVisibleView.findViewById(R.id.section_title);
      TextView secondRowIndex = (TextView) secondVisibleView.findViewById(R.id.section_title);

      int visibleRange = indexList.getChildCount();
      int actual = indexList.getChildPosition(firstVisibleView);
      int next = actual + 1;
      int last = actual + visibleRange;

      // RESET STICKY LETTER INDEX
      stickyIndex.setText(String.valueOf(getIndexContext(firstRowIndex)).toUpperCase());
      stickyIndex.setVisibility(TextView.VISIBLE);
      ViewCompat.setAlpha(firstRowIndex, 1);

      if (dy > 0) {
        // USER SCROLLING DOWN THE RecyclerView
        if (next <= last) {
          if (isHeader(firstRowIndex, secondRowIndex)) {
            stickyIndex.setVisibility(TextView.INVISIBLE);
            firstRowIndex.setVisibility(TextView.VISIBLE);
            ViewCompat.setAlpha(
                firstRowIndex,
                (1 - (Math.abs(ViewCompat.getY(firstVisibleView)) / firstRowIndex.getHeight())));
            secondRowIndex.setVisibility(TextView.VISIBLE);
          } else {
            firstRowIndex.setVisibility(TextView.INVISIBLE);
            stickyIndex.setVisibility(TextView.VISIBLE);
          }
        }
      } else if (dy < 0) {
        // USER IS SCROLLING UP THE RecyclerVIew
        if (next <= last) {
          // RESET FIRST ROW STATE
          firstRowIndex.setVisibility(TextView.INVISIBLE);
          if ((isHeader(firstRowIndex, secondRowIndex)
                  || (getIndexContext(firstRowIndex) != getIndexContext(secondRowIndex)))
              && isHeader(firstRowIndex, secondRowIndex)) {
            stickyIndex.setVisibility(TextView.INVISIBLE);
            firstRowIndex.setVisibility(TextView.VISIBLE);
            ViewCompat.setAlpha(
                firstRowIndex,
                1 - (Math.abs(ViewCompat.getY(firstVisibleView) / firstRowIndex.getHeight())));
            secondRowIndex.setVisibility(TextView.VISIBLE);
          } else {
            secondRowIndex.setVisibility(TextView.INVISIBLE);
          }
        }
      }

      if (stickyIndex.getVisibility() == TextView.VISIBLE) {
        firstRowIndex.setVisibility(TextView.INVISIBLE);
      }
    } else {
      hide();
    }
  }