The entire documentation for the Fragment.onCreateAnimator(int, boolean, int)
method consists of the following text:
"Called when a fragment loads an animation."
That's it. No explanation about the parameters.
What do the parameters mean? Even the source code doesn't reveal much.
The
onCreateAnimator
method is odd. The prototype I've seen is this:public Animator onCreateAnimator(int transit, boolean enter, int nextAnim)
int transit
- transition type, as sandrstar said aboveboolean enter
- true if 'entering,' false otherwiseint nextAnim
- The resource ID of the animation that is about to play.So, for example, if you tried doing a card flip, from the documentation:
NOTE: R.id.container_view in the above example is the ID of a ViewGroup that contains the existing fragment you are trying to replace.
When the above code is executed, the
onCreateAnimator
method will get called, and thenextAnim
parameter will be one of the four animation IDs passed into thesetCustomAnimations()
function, i.e. R.animator.card_flip_right_in, R.animator.card_flip_right_out... etc.This doesn't seem immediately useful at first, since it doesn't give you a reference to the actual Animator object that you could attach a listener to. But oddly, you can just inflate another Animator directly from the
nextAnim
resource, and then attach listeners to that, which will, oddly, fire all the overridden callbacks at the right times:In this way, you should be able to add listeners to the fragment transition animators as if you had created them yourself.
Based on FragmentManager code and usages of FragmentManagerImpl.loadAnimator(android.app.Fragment,int,boolean,int) it seems that Fragment.onCreateAnimator(int, boolean, int) lets You define own animations for fragment hiding, showing, changing state. However, I've never seen usage of it in real apps.
Regarding parameters:
int transit
- transition type (constants FragmentTransaction, e.g. used in here);boolean enter
-true
if it's state enter, false - otherwise;int transitionStyle
- id of style from resources (that style might contain animations missed fromonCreateAnimator
);