I\'m trying to animate the transition between fragments. I got the answer from the following
Android Fragments and animation
FragmentTransaction ft = g
If you can afford to tie yourself to just Lollipop and later, this seems to do the trick:
import android.transition.Slide;
import android.util.Log;
import android.view.Gravity;
.
.
.
f = new MyFragment();
f.setEnterTransition(new Slide(Gravity.END));
f.setExitTransition(new Slide(Gravity.START));
getFragmentManager()
.beginTransaction()
.replace(R.id.content, f, FRAG_TAG) // FRAG_TAG is the tag for your fragment
.commit();
Kotlin version:
f = MyFragment().apply {
enterTransition = Slide(Gravity.END)
exitTransition = Slide(Gravity.START)
}
fragmentManager
.beginTransaction()
.replace(R.id.content, f, FRAG_TAG) // FRAG_TAG is the tag for your fragment
.commit();
Hope this helps.
For anyone else who gets caught, ensure setCustomAnimations is called before the call to replace/add when building the transaction.