Listen to end of animation event for ViewAnimator

183 views Asked by At

I have the following ViewAnimator

<ViewAnimator
    android:padding="12dp"
    android:id="@+id/view_animator"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:animateFirstView="true">

    <include
        android:id="@+id/setup_password_select_type"
        layout="@layout/setup_password_select_type" />

    <include
        android:id="@+id/setup_password_pattern"
        layout="@layout/setup_password_pattern" />

    <include
        android:id="@+id/setup_password_pincode"
        layout="@layout/setup_password_pincode" />


</ViewAnimator>

I perform animation in the following way.

viewAnimator.setInAnimation(slideInRightFast);
viewAnimator.setOutAnimation(slideOutLeftSlow);
viewAnimator.setDisplayedChild(1);

I was wondering, how can I listen to end of animation event?

I tried to use

this.viewAnimator.setLayoutAnimationListener(new Animation.AnimationListener() {
    @Override
    public void onAnimationStart(Animation animation) {

    }

    @Override
    public void onAnimationEnd(Animation animation) {
        android.util.Log.i("CHEOK", "Animation end -> " + viewAnimator.getDisplayedChild());
    }

    @Override
    public void onAnimationRepeat(Animation animation) {

    }
});

But the above is not working.

1

There are 1 answers

0
n.dOubh On

public void setLayoutAnimationListener (Animation.AnimationListener animationListener)

Specifies the animation listener to which layout animation events must be sent.

I guess you want to listen animation child of ViewAnimator, if I'm right:

Your code are listening animation of ViewGroup in this case is ViewAnimator but not it's child

Try this solution if you need:

slideInRightFast.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                Toast.makeText(getApplicationContext(),"START",Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                Toast.makeText(getApplicationContext(),"END",Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
                Toast.makeText(getApplicationContext(),"REPEAT",Toast.LENGTH_SHORT).show();
            }
        });

Wish it can help you. Sorry my bad English.