Java 动画监听器未响应Animatorset
我正在尝试让一个动画在另一个动画结束后开始。我正在使用动画属性,并将对象定义为“AnimatorSet”。问题是第一个动画开始时没有问题,但第二个动画从未开始Java 动画监听器未响应Animatorset,java,android,Java,Android,我正在尝试让一个动画在另一个动画结束后开始。我正在使用动画属性,并将对象定义为“AnimatorSet”。问题是第一个动画开始时没有问题,但第二个动画从未开始 public void moveGround() { ImageView ground = (ImageView) findViewById(R.id.ground); ImageView ground2 = (ImageView) findViewById(R.id.ground2);
public void moveGround() {
ImageView ground = (ImageView) findViewById(R.id.ground);
ImageView ground2 = (ImageView) findViewById(R.id.ground2);
final AnimatorSet moveGround = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.ground_move);
final Animator moveGround2 = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.ground_move2);
moveGround2.setTarget(ground2);
moveGround.setTarget(ground);
moveGround.start();
moveGround.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
moveGround2.start();
}
});
}
编辑:我还尝试在动画侦听器结束后启动第一个动画:相同的结果
编辑2:XML文件
ground_move.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:ordering="sequentially" >
<objectAnimator
android:duration="2000"
android:propertyName="x"
android:repeatCount="infinite"
android:repeatMode="restart"
android:valueFrom="2000"
android:valueTo="-2000"
android:valueType="floatType"
/>
</set>
ground_move2.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:ordering="sequentially" >
<objectAnimator
android:duration="2000"
android:propertyName="x"
android:repeatCount="infinite"
android:repeatMode="restart"
android:valueFrom="2000"
android:valueTo="-2000"
android:valueType="floatType" />
</set>
试试:
(请注意我们如何首先添加侦听器,然后启动动画)如果这不起作用,请尝试设置有限的时间:moveGround.setDuration(有时)代码>在开始之前检查是否正在完成动画
更新
添加xml文件后,我看到您有了android:repeatCount=“infinite”
和android:repeatMode=“restart”
,尝试删除它们或设置android:repeatCount=0
并检查您的侦听器是否正确启动。检查其他方法(onAnimationCancel()、onAnimationPause()、onAnimationRepeat()(),onAnimationResume()
),打印日志,可能正在其他地方暂停。啊,是的,所以当我尝试使用“onAnimationStart()”时,它会启动为什么它不启动其他方法?添加xml文件s:很抱歉响应太晚。我添加了xml文件。感谢agianThanks的提示响应。我尝试了这个方法,但它也不起作用。我还添加了setDuration,但它不起作用。:(是的!动画在我删除repeatCount(或将其设置为0)后启动)当我按照您的建议删除repeatMode时。如何让第一个模式再次循环?这是一个好问题,解决方法是在第二个animator对象的新侦听器中重新启动动画
moveGround.setTarget(ground);
moveGround.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
moveGround2.start();
}
});
moveGround.start();