I found a way to add the Animator
.
It is achieved by overriding the fragment's onCreateAnimator
method before adding it to the fragmentManager. As an example, to slide the animation in and out during transition you can do this:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tutorial);
if (savedInstanceState == null) {
Fragment fragment = new MyFragment(){
@Override
public Animator onCreateAnimator(int transit, boolean enter, int nextAnim)
{
Display display = getActivity().getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
Animator animator = null;
if(enter){
animator =
ObjectAnimator.ofFloat(this, "translationX", (float) size.x, 0);
} else {
animator =
ObjectAnimator.ofFloat(this, "translationX", 0, (float) size.x);
}
animator.setDuration(500);
return animator;
}
}
getFragmentManager().beginTransaction()
.add(R.id.container, fragment)
.commit();
}
}
P.S. this answer is thanks to a post in question section of this forum.