3

I want slide up animation when opening Fragment B. And when going Back from Fragment B to A, I need the animation in reverse order.

I have an Activity which contains a Fragment A, I open Fragment B from A using the given code with animation.

    FragmentTransaction ft = fm.beginTransaction();
    ft.setCustomAnimations(R.anim.slide_in_from_bottom, R.anim.slide_out_from_bottom);
    ft.replace(R.id.container, fragment);
    ft.addToBackStack("");
    ft.commit();

Where

slide_in_from_bottom

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator">

    <translate
        android:duration="@integer/anim_duration"
        android:fromYDelta="100%p"
        android:toYDelta="0" />
</set>

slide_out_from_bottom

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator">

    <translate
        android:duration="@integer/anim_duration"
        android:fromYDelta="0"
        android:toYDelta="-100%p" />
</set>

Everything working fine. Now I want to show the animation in reverse order while going Back from B to Fragment A.

I use this code but it's not working why is it so?

FragmentTransaction ft = fm.beginTransaction();
ft.setCustomAnimations(R.anim.slide_out_from_bottom, R.anim.slide_in_from_bottom
            , R.anim.slide_in_from_bottom, R.anim.slide_out_from_bottom);
 fm.popBackStack();
 ft.commit();
Zar E Ahmer
  • 33,936
  • 20
  • 234
  • 300

0 Answers0