I am trying to achieve the following effect using FragmentTransaction.setCustomAnimations.
I found an alternate solution (not heavily tested) that I find more elegant than the proposals so far:
final IncomingFragment newFrag = new IncomingFragment();
newFrag.setEnterAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
clearSelection();
inFrag.clearEnterAnimationListener();
getFragmentManager().beginTransaction().remove(OutgoingFragment.this).commit();
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
getActivity().getSupportFragmentManager().beginTransaction()
.setCustomAnimations(R.anim.slide_in_from_right, 0)
.add(R.id.container, inFrag)
.addToBackStack(null)
.commit();
This is being called from within an inner class of the OutgoingFragment class.
A new fragment is being inserted, the animation completes, then the old fragment is being removed.
There may be some memory problems with this in some applications but it is better than retaining both fragments indefinitely.