title: Dynamically animate a layout
body: <p>I have to implement a (child) layout translate animation programmatically because the distance to translate is determined at runtime. I have set the following translate animation</p>
  
  <pre><code>    TranslateAnimation tanim = new TranslateAnimation(
          TranslateAnimation.ABSOLUTE, 0.0f,
          TranslateAnimation.ABSOLUTE, 0.0f,
          TranslateAnimation.ABSOLUTE, 0.0f,
          TranslateAnimation.ABSOLUTE, 100);
  </code></pre>
  
  <p>to slide down the layout, for example.</p>
  
  <p><strong>Problem 1:</strong> This layout will snap back to its original position after the animation finishes. Is there anything I should set to maintain its position? I suspect this is caused by the layout being moved out of the parent layout (parent layout has parameter <code>layout_width="wrap_content"</code>). If this is the case how can I adjust the parent layout to accomodate the child layout change?</p>
  
  <p><strong>Problem 2:</strong> Do I have to provide a custom interpolator class to achieve a decelerating effect? If yes, do you know where can I find an example? In xml I can do this</p>
  
  <pre><code>android:interpolator="@android:anim/accelerate_interpolator"
  </code></pre>
  
  <p>Is there an equivalent Android code to achieve the accelerate/decelerate effect programmatically?</p>