title: LayoutTransition.DISAPPEARING animations don't run when removing child views
body: <p>I have a <code>FrameLayout</code> container that I'm trying to have animate it's changes.  I call <code>container.setLayoutTransition(layoutTransition)</code> on the view, but when I later call <code>container.removeView(v)</code> the <code>DISAPPEARING</code> animation isn't executed, the view is simply immediately removed.</p>
  
  <p>Here's my code for the transition:</p>
  
  <pre><code>LayoutTransition layoutTransition = new LayoutTransition();
  layoutTransition.setAnimator(LayoutTransition.APPEARING,
      ObjectAnimator.ofFloat(null, View.TRANSLATION_Y, toolHeight, 0f));
  layoutTransition.setStartDelay(LayoutTransition.APPEARING, 0);
  layoutTransition.setDuration(LayoutTransition.APPEARING, 1000);
  layoutTransition.setAnimator(LayoutTransition.DISAPPEARING,
      ObjectAnimator.ofFloat(null, View.TRANSLATION_Y, 0f, toolHeight));
  layoutTransition.setStartDelay(LayoutTransition.DISAPPEARING, 0);
  layoutTransition.setDuration(LayoutTransition.DISAPPEARING, 1000);
  container.setLayoutTransition(layoutTransition);
  </code></pre>
  
  <p>And to swap views I do this:</p>
  
  <pre><code>if (container.getChildCount() &gt; 0) {
    for (int i = container.getChildCount() - 1; i &gt;= 0; i--) {
      container.removeViewAt(i);
    }
  }
  container.addView(newView);
  </code></pre>
  
  <p>I've slowed down the animations to confirm the situation, and I can clearly see that the <code>APPEARING</code> transition is executed appropriately, but the <code>DISAPPEARING</code> transition isn't, the view is simply removed immediately.</p>
  
  <p>I've found that if I remove the view from the <code>LayoutTransition.removeChild()</code> method it works, but that adds quite a bit of complexity that doesn't seem necessary.  Here's what that becomes:</p>
  
  <pre><code>if (container.getChildCount() &gt; 0) {
    final View v = container.getChildAt(0);
    container.getLayoutTransition().removeChild(container, v);
    container.getLayoutTransition().addTransitionListener(new LayoutTransition.TransitionListener() {
      @Override
      public void startTransition(LayoutTransition transition, ViewGroup container, View view, int transitionType) {
      }
  
      @Override
      public void endTransition(LayoutTransition transition, ViewGroup container, View view, int transitionType) {
        transition.removeTransitionListener(this);
        if (transitionType == LayoutTransition.DISAPPEARING) {
          container.removeView(view);
        }
      }
    }
  }
  container.addView(newView);
  </code></pre>
  
  <p>Think that's bad?  That's only for removing a single view at a time, if there is more than one view in the container then I've got to add a transition listener that counts executions to know when to remove itself, and that's just a mess.</p>
  
  <p>The removing itself is interesting, because if I simply put that transition listener on the <code>LayoutTransition</code> and it doesn't remove itself, then the disappearing transition doesn't run again.</p>
  
  <p>Clearly I'm missing something pertaining to making the remove transition execute.  Any help would be appreciated.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>It's been pointed out to me that adding views cancels the <code>DISAPPEARING</code> transitions:</p>
  
  <pre><code>public class ViewGroup {
    private void addViewInner(...) {
      if (mTransition != null) {
        // Don't prevent other add transitions from completing, but cancel remove
        // transitions to let them complete the process before we add to the container
        mTransition.cancel(LayoutTransition.DISAPPEARING);
      }
    }
  }
  </code></pre>
  
  <p>This doesn't make a lot of sense to me.  Wonder what the reasoning is here.</p>