FragmentTransaction setTransition() for remove() doesn't change the transition previously set in replace()

StackOverflow https://stackoverflow.com/questions/22464284

سؤال

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 set TRANSIT_NONE.

Any thoughts?

هل كانت مفيدة؟

المحلول

  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

نصائح أخرى

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top