1

I use custom fragment animations. xml files are below:

Bottom to top:

<?xml version="1.0" encoding="utf-8" ?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_decelerate_interpolator">
    <translate android:duration="350" android:fromXDelta="0%" android:fromYDelta="100%" android:toXDelta="0%" android:toYDelta="0%" />
</set>

Top to bottom:

<?xml version="1.0" encoding="utf-8" ?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator">
    <translate android:duration="350" android:fromXDelta="0%" android:fromYDelta="0%" android:toXDelta="0%" android:toYDelta="100%" />

</set>

This example works as expected:

FragmentTransaction ft = fragmentManager.beginTransaction();
ft.setCustomAnimations(0, R.anim.top_to_bottom);
ft.replace(R.id.main_layout, fragmentA, fragmentA.ID);
ft.commit();

But this example doesn't work for me. I see blank screen on transition. Fragment A disappears, blank screen exists while fragmentB rises up.

FragmentTransaction ft = fragmentManager.beginTransaction();
ft.setCustomAnimations(R.anim.bottom_to_top, 0);
ft.replace(R.id.main_layout, fragmentB, fragmentB.ID);
ft.commit();
zakjma
  • 2,030
  • 12
  • 40
  • 81

2 Answers2

0

Try to add this line, because you are replacing the previous fragment with the new one, it is showing you a blank screen.

FragmentTransaction ft = fragmentManager.beginTransaction();
ft.setCustomAnimations(R.anim.bottom_to_top, 0);
ft.replace(R.id.main_layout, fragmentB, fragmentB.ID);

// This line will maintain previous fragment in stack
ft.addToBackStack(fragmentB.getClass().getSimpleName());

ft.commit();
Hamza Khan
  • 1,433
  • 13
  • 19
0

Try adding pop enter and pop exit animation like this :

            supportFragmentManager.beginTransaction().setCustomAnimations(R.anim.enter, R.anim.exit, R.anim.enter, R.anim.exit).replace(R.id.container, fragment).commit()
ROHIT LIEN
  • 497
  • 3
  • 8