I apply some animation for fragment translation. Can I add an animation listener to detect the animation start/end event?
Thanks all.
You can if you override onCreateAnimation()
(or onCreateAnimator()
if you are using 3.0+ fragments...both allow listeners) inside of your custom fragment to provide the animations rather than using the custom animation methods of 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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With