FragmentTransaction setTransition() for remove() doesn't change the transition previously set in replace()
13,477
Solution 1
public void mRemoveFragment(android.app.Fragment fragment){
android.app.FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);
ft.remove(fragment);
ft.commit();
}
use this function to remove the fragment. Where in setCustomAnimation, you can give your scripts. I have currently used the default ones provided by android
Solution 2
Try using a custom animation with the FragmentTransaction:
fragmentTransaction.setCustomAnimations(R.anim.frag_fade_in, R.anim.frag_fade_out, R.anim.frag_fade_in, R.anim.frag_fade_out);
Resources here :: Custom animations for fragment transactions
Author by
fcasanova
Updated on June 13, 2022Comments
-
fcasanova almost 2 years
So, first of all I create a new Fragment like this
ft = fm.beginTransaction(); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); ft.replace(R.id.main_content_frame, cFr, "CARS"); ft.addToBackStack(null); ft.commit();
And later I remove it like this
fm.popBackStack(); ft = fm.beginTransaction(); ft.setTransition(FragmentTransaction.TRANSIT_NONE); ft.remove(fm.findFragmentByTag("CARS")).commit();
But the close transition is done with the
TRANSIT_FRAGMENT_OPEN
animation (or its opposite by default, I think), and I clearly setTRANSIT_NONE
.Any thoughts?