我有以下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>
我以以下方式执行动画。
viewAnimator.setInAnimation(slideInRightFast);
viewAnimator.setOutAnimation(slideOutLeftSlow);
viewAnimator.setDisplayedChild(1);
我想知道如何收听动画事件的结束?
我尝试使用
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) {
}
});
但是上面的方法不起作用。
答案 0 :(得分:0)
公共无效setLayoutAnimationListener(Animation.AnimationListener animationListener)
指定动画侦听器必须对其进行布局动画事件 被发送。
我猜你想听ViewAnimator
的动画子集,
您的代码中ViewGroup
的监听动画是ViewAnimator
,但不是孩子
如果需要,请尝试以下解决方案:
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();
}
});
希望它能对您有所帮助。对不起,我的英语不好。