title: Collapse animation on android layout
body: <p>i got this problem, i have an accordion like activity, with buttons that expands or collapse layouts depending of its state, then the problem is in the animations, the expand animation it's just perfect, but the collapse one when collapsing the layout it pass above of the parent button and i want to collapse it relative of the layout.</p>
  
  <p>sorry fo my bad english, here's the code:</p>
  
  <pre><code>public class Animations extends Animation {
  
  /**
   * Initializes expand collapse animation, has two types, collapse (1) and expand (0).
   * @param view The view to animate
   * @param duration
   * @param type The type of animation: 0 will expand from gone and 0 size to visible and layout size defined in xml. 
   * 1 will collapse view and set to gone
   */
  public AnimationSet AnimationSet;
  
  public Animations(String type) {
      if (type == "Expand")
          AnimationSet = ExpandAnimation();
      if (type == "Collapse")
          AnimationSet =  CollapseAnimation();    
  }
  public AnimationSet ExpandAnimation() {
  
      AnimationSet _set = new AnimationSet(true);
  
        Animation animation = new AlphaAnimation(0.0f, 1.0f);
        animation.setDuration(250);
        _set.addAnimation(animation);
  
        animation = new TranslateAnimation(
            Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
            Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f
        );
        animation.setDuration(150);
        _set.addAnimation(animation);
  
        return _set;
  
  }
  public AnimationSet CollapseAnimation() {
  
      AnimationSet set = new AnimationSet(true);
  
        Animation animation = new AlphaAnimation(1.0f, 1.0f);
        animation.setDuration(250);
        set.addAnimation(animation);
  
        animation = new TranslateAnimation(
            Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
            Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -1.0f
        );
        animation.setDuration(250);
        set.addAnimation(animation);
  
        return set;
  
  }
  </code></pre>
  
  <p>}</p>