Can I add an AnimationListener to translate fragments

I use some animation to translate the fragment. Can I add an animation listener to detect the start / end of an animation?

Thanks to everyone.

+4
source share
1 answer

You can if you override onCreateAnimation() (or onCreateAnimator() if you use 3.0 + snippets ... both allow listeners) inside your custom snippet to provide animation rather than using custom animation methods FragmentTransaction

 @Override public Animation onCreateAnimation (int transit, boolean enter, int nextAnim) { Animation anim; if (enter) { anim = AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_in); } else { anim = AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_out); } anim.setAnimationListener(new AnimationListener() { public void onAnimationEnd(Animation animation) { } public void onAnimationRepeat(Animation animation) { } public void onAnimationStart(Animation animation) { } }); return anim; } 
+12
source

All Articles