Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I add AnimationListener for Fragment translation

I apply some animation for fragment translation. Can I add an animation listener to detect the animation start/end event?

Thanks all.

like image 527
King Wu Avatar asked Jul 18 '12 16:07

King Wu


1 Answers

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;
}
like image 98
devunwired Avatar answered Nov 04 '22 10:11

devunwired