2
FragmentTransaction t = getFragmentManager().beginTransaction() ;
            //left to right
            t.setCustomAnimations(R.anim.left_to_right, R.anim.left_to_right_out);

i have an animation in FragmentTransaction. is there any way to know when the animation is finished or any animationListener analogue?

Korniltsev Anatoly
  • 3,676
  • 2
  • 26
  • 37
  • Maybe this can answer your question: http://stackoverflow.com/questions/11120372/performing-action-after-fragment-transaction-animation-is-finished – Uilque Messias Feb 16 '17 at 20:37

1 Answers1

0

I've never worked with Fragments but I've had a similar issue with a scrollView once. I wanted to know when the scroll ended. Something you could probably do is implement your own listener. You could make a runnable (animationTask) and have that runnable check to see if some condition has been met to determine if the animation has ended and if not, keep calling the runnable.

In order to do this you'd need to make your own FragmentTransaction Class that extends FragmentTransaction and declare an interface (which will be your listener).

public abstract class M_FragmentTransaction extends FragmentTransaction {
private Runnable animationTask;
public interface OnAnimationFinish{
    void onAnimationStopped();
}

private OnAnimationFinish onAnimationFinishListener;

public M_FragmentTransaction() {
    super();
    animationTask = new Runnable() {

        public void run() {

            while(!SOMETHING_TO_DETERMINE_IF_HAS_STOPPED){//has stopped

                if(onAnimationFinishListener!=null){

                    onAnimationFinishListener.onAnimationStopped();
                }
            }
        }
    };
}

public void setOnAnimationFinish(OnAnimationFinish listener){
    onAnimationFinishListener = listener;
}

public void startAnimationStart(){

    animationTask.run();
}

Now in your posted code you'd put this you would have to look into converting the FragmentTransaction returned from getFragmentManager().beginTransaction(); into a M_FragmentTransaction since you can't do child = parent. I'm not too sure if this is more trouble than it's worth, but this approach helped me solve my problem.

Hope this helps!

zabawaba99
  • 507
  • 1
  • 6
  • 13
  • how am i suppossed to create my own transaction if transactions are created by FragmentManager? your code is blocking UI thread i'm pretty shure there will be no animation at all. I know the duration of animation and i don't whant to guess whether the animation is finished, i need some kind of callback or something simmilar – Korniltsev Anatoly Oct 05 '12 at 20:01