title: Slide up and Down animation for Fragment transaction in Android
body: <p>I am developing an app in Android. I am using a flow to take information form the user. To build the flow I am using few fragments. There are five steps and I am using five fragments. I am using another fragment to show the previous records he saved using list view. In my activity I am using a button named Expand. The button Expand is used to show the previous records using fragment. When the user clicks on the button Expand the fragment will take place and the Expand button text will be set to Hide. When the button text is Hide, if the user clicks on the button again the fragment will be removed from the stack and the previous fragment added to the back stack will be shown. </p>
  
  <p>For example let us assume that I have five fragments named FragmentA, FragmentB, FragmentC, FragmentD, FragmentE and another fragment named ProjectRowsFragment which will be used to show the records previously saved in a ListView on the click event of the button named Expand.</p>
  
  <p>Let us assume that the user is in FragmentC and he clicked on the Expand button. What will happen is that FragmentC will be replaced and ProjectRowsFragment will be added. If the user clicks on the button again the ProjectRowsFragment will be replaced and the FragmentC will come in from back stack. If it was FragmentD then it will be replaced and ProjectRowsFragment will be added and if user clicks on the button again ProjectRowsFragment will be replaced and FragmentD will come in from back stack. </p>
  
  <p>I have done with the transactions. </p>
  
  <p>What I want is that I want animation to be added while the ProjectRowsFragment (The fragment I am using to show the records) is shown and replaced. When it is shown it will slide down from the top and then when it is removed from the back stack it will slide up. </p>
  
  <p>After trying a lot I accomplished the slide down effect, but how can I get the slide up animation.</p>
  
  <p>Here is my codes.</p>
  
  <pre><code>fragmentManager = getFragmentManager();
  fragmentTransaction = fragmentManager.beginTransaction();
  fragmentTransaction.setCustomAnimations(R.animator.slide_in_from_top, 0, R.animator.slide_in_from_bottom, 0);
  fragmentTransaction.replace(R.id.fragment_container, ProjectRowsFragment.newInstance(this.projectId));
  fragmentTransaction.addToBackStack(null);
  fragmentTransaction.commit();
  projectRowsExpanded = true;
  </code></pre>
  
  <p>slide_in_from_top.xml file is </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;set xmlns:android="http://schemas.android.com/apk/res/android"
  android:fillAfter="true" &gt;
  &lt;objectAnimator
      android:duration="600"
      android:propertyName="y"
      android:valueFrom="-1280"
      android:valueTo="0"
      android:valueType="floatType" /&gt;
  &lt;/set&gt;
  </code></pre>
  
  <p>Here i have three images to visualize </p>
  
  <p>Initial Step </p>
  
  <p><a href="https://i.stack.imgur.com/5sLHu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5sLHu.png" alt="enter image description here"></a></p>
  
  <p>If the user clicks on the button indicated a list will be placed. </p>
  
  <p><a href="https://i.stack.imgur.com/AqTH5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AqTH5.png" alt="enter image description here"></a></p>
  
  <p>If the user clicks again in the indicated button. </p>
  
  <p><a href="https://i.stack.imgur.com/pzpkS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pzpkS.png" alt="enter image description here"></a></p>