Q:

Why my custom Behavior doesn't work well in Android

I have an ImageView in the top of the layout and a RecyclerView below it; That's all I need in my custom Behavior step 1;  But, it doesn't seem to work well.  
Here is the code:
Behavior.java
public class Depency extends CoordinatorLayout.Behavior<RecyclerView> {
  private String TAG = "tag";

  public Depency() {
  }

  public Depency(Context context, AttributeSet attrs) {
    super(context, attrs);
  }

  @Override
  public boolean onDependentViewChanged(CoordinatorLayout parent, RecyclerView child, View
        dependency) {
    int delta = (int) (dependency.getTranslationY() + dependency.getBottom());
    delta -= child.getTop();
    child.offsetTopAndBottom(delta);
    Log.i(TAG,
          "onDependentViewChanged: " + delta + "," + child.getTop() + dependency.getClass().getSimpleName());
    return true;
  }

  @Override
  public boolean layoutDependsOn(CoordinatorLayout parent, RecyclerView child, View dependency) {
    return dependency instanceof AppCompatImageView;
  }
}

layout.xml
<android.support.design.widget.CoordinatorLayout
    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"
   tools:context="com.example.kenchan.fullypjo.MainActivity"
   tools:showIn="@layout/activity_main">

  <android.support.v7.widget.AppCompatImageView
    android:id="@+id/imageView"
    android:layout_width="match_parent"
    android:layout_height="150dp"
    android:scaleType="centerCrop"
    android:src="@drawable/ic_girl"/>

  <android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="com.example.kenchan.fullypjo.view.Depency"/>

</android.support.design.widget.CoordinatorLayout>

The preview in xml:

seems work fine.
But when I run the project on my cell phone , I get wrong:

Could somebody help me or advise me with my code ?
The problem has bothered me for a while;
I tried to read source code in android.support.design.widget.AppBarLayout$ScrollingViewBehavior
and I found the code logic just at different nothing:
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, View child,
            View dependency) {
   offsetChildAsNeeded(parent, child, dependency);
   return false;
}

private void offsetChildAsNeeded(CoordinatorLayout parent, View child, View dependency) {
  final CoordinatorLayout.Behavior behavior =
                ((CoordinatorLayout.LayoutParams) dependency.getLayoutParams()).getBehavior();
  if (behavior instanceof Behavior) {
       // Offset the child, pinning it to the bottom the header-dependency, maintaining
     // any vertical gap and overlap
     final Behavior ablBehavior = (Behavior) behavior;
     ViewCompat.offsetTopAndBottom(child, (dependency.getBottom() - child.getTop())
                    + ablBehavior.mOffsetDelta
                    + getVerticalLayoutGap()
                    - getOverlapPixelsForOffset(dependency));
  }
}

A:

RecyclerView is at top z-index, that's why you are seeing it as overlayed over the ImageView. In the preview you see it with only see 9 items. 
You need to change RecyclerView top when inside your Behavior's onLayoutChild() method, to the bottom of the ImageView. This method gives you a chance to lay out the child yourself, instead of allowing CoordinatorLayout to do it deliberately. If you return true, CoordinatorLayout will not attempt to layout that view. 

