I want to animate a fragment on opening and closing. I have a fade in and a fade out custom animation XML files.
I'm using setCustomAnimations on my support FragmentTransaction, but all it does is animating when I do the addToBackStack, when I do a popBackStack it just disappears without animation.
Here's a snippet of my code:
private void fragmentAppear(){
fragment = new LoginFragment();
fragmentManager = LoginActivity.this.getSupportFragmentManager();
fragmentTransaction = fragmentManager.beginTransaction();
//my XML anim files
fragmentTransaction.setCustomAnimations(R.anim.slide_in_bottom,0,0,R.anim.slide_out_bottom);
fragmentTransaction.replace(R.id.login_fragment, fragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
private void fragmentDisappear(){
getSupportFragmentManager().popBackStack();
}
On the setCustomAnimations part I'm using the 4 params and so far it only shows the fade out animation right before the slide in when I call fragmentAppear, but never when calling fragmentDisappear. I have already tried ordering the parameters in many, many different ways, also I have tried with the two param version of setCustomAnimations and all it does is animating when the fragment appears.
I'm using android.support.v4.app library for my fragments.
EDIT: Also, the animation won't show when pressing the back button without calling fragmentDisappear either.
The past code is in the activity, I tried to do a popBackStack from the fragment and it isn't working either. Is it the right way to close my fragment?
EDIT: I will include the XML animations:
slide_in_bottom.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="75%p"
android:toYDelta="0%p"
android:fillAfter="true"
android:duration="400" />
</set>
slide_out_bottom.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="0%p"
android:toYDelta="75%p"
android:fillAfter="true"
android:duration="400" />
</set>