title: How to slide a view in and out in android
body: <p>I'm trying to make a view <em>(Linear view with some buttons in - <code>R.id.playerControl</code>)</em> slide in and out based on the context of other events in the activity.  </p>
  
  <p>For this purpose I've got a <code>selectMediaItem</code> method which should show or hide the view when the user selects or deselects an item respectively.</p>
  
  <p>I'm new with animation in android and I'm having trouble getting this to work for two reasons:</p>
  
  <ol>
  <li><p>The view remains on screen outside the animation time, so when it has finished sliding out it jumps back in - then when requested to slide in it jumps out to slide back in.</p></li>
  <li><p>There is a permanent black space on the screen as the view disappears.  I'd like the view to fill space when when visible and be <code>GONE</code> when not.  To this end I'd like the layout to change with the animation as well so that it appears to push other things out of the way.</p></li>
  </ol>
  
  <p>My Code:</p>
  
  <pre><code>protected void selectMediaItem( ItemHandle item ) {
  
      if (item != null) {
          if (toPlay == null) {
              View playerControl = findViewById(R.id.playerControl);
              Animation slideInAdmination = AnimationUtils.loadAnimation(this, R.anim.slide_in);
              playerControl.startAnimation(slideInAdmination);
          }
      }
      else {
          if (toPlay != null) {
              View playerControl = findViewById(R.id.playerControl);
              Animation slideInAdmination = AnimationUtils.loadAnimation(this, R.anim.slide_out);
              playerControl.startAnimation(slideInAdmination);
          }
      }
      toPlay = item;
  }
  </code></pre>
  
  <p>slide_in.xml
      
      </p>
  
  <pre><code>    &lt;translate
          android:duration="1000"
          android:fromYDelta="100%p"
          android:toYDelta="0" /&gt;
  
  
  &lt;/set&gt;
  </code></pre>
  
  <p>Is there a simple way to slide a view into place and slide it out again?</p>