title: An easy way to make GONE animation work
body: <p>I have a custom search panel, which is a part of main layout. Most of time the panel is hidden. I would like to add appearing/disappearing animation to the panel. Here is the simplified layout excerpt:</p>
  
  <pre><code>&lt;LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical" &gt;
      &lt;RelativeLayout
          android:id="@+id/layoutSearch"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:visibility="gone" &gt;
          &lt;EditText
              android:id="@+id/editSearch"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content" /&gt;
          &lt;&lt;Other inner views to be animated&gt;&gt;
      &lt;/RelativeLayout&gt;
      &lt;&lt;Other views, which should not be affected by the animation&gt;&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>Try 1</strong>: I added animation resources and attach them to the @id/layoutSearch with this line in XML:</p>
  
  <pre><code>android:layoutAnimation="@anim/search_in_layout"
  </code></pre>
  
  <p>anim/search_in.xml:</p>
  
  <pre><code>&lt;translate
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:interpolator="@android:anim/overshoot_interpolator"
      android:fromYDelta="-100%p"
      android:toYDelta="0"
      android:duration="@android:integer/config_longAnimTime" /&gt;
  </code></pre>
  
  <p>anim/search_in_layout.xml:</p>
  
  <pre><code>&lt;layoutAnimation
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:animation="@anim/search_in" /&gt;
  </code></pre>
  
  <p>The animation works fine, but only for the panel appearing. The panel disappears in a moment without animation when I hide it with:</p>
  
  <pre><code>mSearchLayout.setVisibility(View.GONE);
  </code></pre>
  
  <p><strong>Try 2</strong>: I guess the above solution does not work as the animation destination parameters match the current panel position. OK, I created two more animation resources: anim/search_out.xml and anim/search_out_layout.xml. The only differences are exchanged "fromYDelta" and "toYDelta" values and updated "android:animation" value. Then I load the resources in the code and set them to the @id/layoutSearch like this:</p>
  
  <pre><code>LayoutAnimationController controller =
      AnimationUtils.loadLayoutAnimation(this, R.anim.search_out_layout);
  mSearchLayout.setLayoutAnimation(controller);
  </code></pre>
  
  <p>The "out" animation triggered on calling of setLayoutAnimation(). After the animation the search panel returns to it original position on the screen it had before "out" animation. If I try to call mSearchLayout.setVisibility(View.GONE) just after setLayoutAnimation(), I see no animation, the panel disappears at once.</p>
  
  <p><strong>Try 3</strong>: I guess I need to create the animation in the code and then set a listener on it. Then I should call mSearchLayout.setVisibility(View.GONE) in the onAnimationEnd() handler to hide the panel after the animation played. I did not tried this yet. I think it's over complicated.</p>
  
  <p>I guess I missed something important. Is there a way to implement GONE animation a bit easy?</p>