title: CoordinatorLayout: View disappears with custom behavior
body: <p>I am a newbie to <code>CoordinatorLayout</code> and this is a really strange behavior I am getting in <code>CoordinatorLayout</code>.I have an <code>ImageView</code>(or more specifically a subclass of <code>ImageView</code> called <code>CircleImageView</code><em>(it houses the Profile pic in the center here)</em>) as one of the children of the <code>CoordinatorLayout</code>. I have anchored this <code>CircleImageView</code> to the <code>AppbarLayout</code>(which is another child of the <code>CoordinatorLayout</code>). Here is the entire layout I have:</p>
  
  <p><img src="https://i.stack.imgur.com/vN5Sp.png" width="400"></p>
  
  <p>So far so good. I am currently able to scroll the <code>AppbarLayout</code> and the <code>NestedScrollView</code> moves along with it. But, I thought of animating the Profile pic to move to right as we scroll up and decided to rely on custom <code>CoordinatorLayour.Behavior</code>. I ended up with a custom behavior that tries translation of the <code>CircleImageView</code>. It's not complete yet but is supposed to translate the view roughly some amount except now, the <code>CircleImageView</code> has disappeared completely with the introduction of custom behavior.</p>
  
  <p>What might be the reason for this?</p>
  
  <p><strong><em>Note</strong>: I have tried replacing the CircleImageView with an ImageView and the behavior remains the same.</em></p>
  
  <hr>
  
  <p>Here is the layout for reference:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;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"
      android:fitsSystemWindows="false"&gt;
  
      &lt;android.support.design.widget.AppBarLayout
          android:id="@+id/main.appbar"
          android:layout_width="match_parent"
          android:layout_height="200dp"
          android:fitsSystemWindows="false"
          android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"&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"&gt;
  
              &lt;android.support.v7.widget.Toolbar
                  android:id="@+id/toolbar"
                  android:layout_width="match_parent"
                  android:layout_height="?attr/actionBarSize"
                  android:background="?attr/colorPrimary"
                  app:layout_collapseMode="pin"
                  app:popupTheme="@style/ThemeOverlay.AppCompat.Light"&gt;
  
              &lt;/android.support.v7.widget.Toolbar&gt;
  
              &lt;android.support.v7.widget.AppCompatImageView
                  android:id="@+id/imageView"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_gravity="bottom|end"
                  android:layout_marginBottom="24dp"
                  android:layout_marginEnd="24dp"
                  android:layout_marginRight="24dp"
                  android:layout_weight="1"
                  android:tint="@color/white"
                  app:srcCompat="@drawable/ic_settings_24px" /&gt;
  
          &lt;/android.support.design.widget.CollapsingToolbarLayout&gt;
  
  
      &lt;/android.support.design.widget.AppBarLayout&gt;
  
      &lt;de.hdodenhof.circleimageview.CircleImageView
          android:id="@+id/profile_pic"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:elevation="4dp"
             app:layout_behavior="com.learncity.learner.account.profile.ProfilePicBehavior"
          android:src="@drawable/avatar_boy_2"
          app:layout_anchor="@id/main.appbar"
          app:layout_anchorGravity="bottom|center" /&gt;
  
      &lt;android.support.v4.widget.NestedScrollView
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:fillViewport="true"
          app:layout_behavior="@string/appbar_scrolling_view_behavior"&gt;
  
          &lt;android.support.constraint.ConstraintLayout
              android:layout_width="match_parent"
              android:layout_height="match_parent"&gt;
  
  
              &lt;TextView
                  android:id="@+id/user_name"
                  android:layout_width="0dp"
                  android:layout_height="wrap_content"
                  android:layout_marginEnd="8dp"
                  android:layout_marginLeft="8dp"
                  android:layout_marginRight="8dp"
                  android:layout_marginStart="8dp"
                  android:layout_marginTop="64dp"
                  android:lineSpacingExtra="8dp"
                  android:padding="@dimen/activity_horizontal_margin"
                  android:text="@string/account_person_name_label"
                  android:textAlignment="center"
                  android:textSize="40sp"
                  app:layout_constraintHorizontal_bias="0.0"
                  app:layout_constraintLeft_toLeftOf="parent"
                  app:layout_constraintRight_toRightOf="parent"
                  app:layout_constraintTop_toTopOf="parent" /&gt;
  
              &lt;android.support.v7.widget.AppCompatImageView
                  android:id="@+id/id_phone_icon"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_marginLeft="24dp"
                  android:layout_marginStart="24dp"
                  android:layout_marginTop="8dp"
                  android:tint="@color/colorPrimary"
                  app:layout_constraintLeft_toLeftOf="parent"
                  app:layout_constraintTop_toBottomOf="@+id/user_name"
                  app:srcCompat="@drawable/ic_phone_black_24dp" /&gt;
  
              &lt;TextView
                  android:id="@+id/id_phone_no"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_marginLeft="16dp"
                  android:layout_marginStart="16dp"
                  android:text="Phone No"
                  app:layout_constraintBottom_toBottomOf="@+id/id_phone_icon"
                  app:layout_constraintLeft_toRightOf="@+id/id_phone_icon"
                  app:layout_constraintTop_toTopOf="@+id/id_phone_icon"
                  app:layout_constraintVertical_bias="0.571" /&gt;
  
  
              &lt;android.support.v7.widget.AppCompatImageView
                  android:id="@+id/id_email_icon"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_marginLeft="24dp"
                  android:layout_marginStart="24dp"
                  android:layout_marginTop="8dp"
                  android:tint="@color/colorPrimary"
                  app:layout_constraintLeft_toLeftOf="parent"
                  app:layout_constraintTop_toBottomOf="@+id/id_phone_icon"
                  app:srcCompat="@drawable/ic_email_black_24dp" /&gt;
  
              &lt;TextView
                  android:id="@+id/id_email_id"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_marginLeft="16dp"
                  android:layout_marginStart="16dp"
                  android:text="Email Id"
                  app:layout_constraintBottom_toBottomOf="@+id/id_email_icon"
                  app:layout_constraintLeft_toRightOf="@+id/id_email_icon"
                  app:layout_constraintTop_toTopOf="@+id/id_email_icon" /&gt;
  
              &lt;View
                  style="@style/Divider"
                  android:layout_marginEnd="8dp"
                  android:layout_marginLeft="8dp"
                  android:layout_marginRight="8dp"
                  android:layout_marginStart="8dp"
                  android:layout_marginTop="8dp"
                  app:layout_constraintTop_toBottomOf="@+id/id_email_icon" /&gt;
  
          &lt;/android.support.constraint.ConstraintLayout&gt;
  
      &lt;/android.support.v4.widget.NestedScrollView&gt;
  
  
  &lt;/android.support.design.widget.CoordinatorLayout&gt;
  </code></pre>
  
  <p>And the custom behavior:(<em>I know the calculations might not be sound but I am trying for an initial crude animation</em>)</p>
  
  <pre><code>public class ProfilePicBehavior extends CoordinatorLayout.Behavior&lt;CircleImageView&gt;{
  
  
      public ProfilePicBehavior(Context context, AttributeSet attrs) {
          super(context, attrs);
      }
  
      @Override
      public boolean layoutDependsOn(CoordinatorLayout parent, CircleImageView child, View dependency) {
          return dependency instanceof AppBarLayout;
      }
  
      @Override
      public boolean onDependentViewChanged(CoordinatorLayout parent, CircleImageView child, View dependency) {
          // Translate the CircleImageView to the right
          // Calculate first, what fraction the AppBarLayout has shrunk by
          float proportion = dependency.getHeight() / 200f;
          // Translate the child by this proportion
          float translationX = parent.getWidth() * proportion;
          child.setTranslationX(translationX);
  
          return true;
      }
  }
  </code></pre>