gpt4 book ai didi

java - 动画监听器不响应 Animatorset

转载 作者:行者123 更新时间:2023-11-30 10:58:59 26 4
gpt4 key购买 nike

我正在尝试让一个动画在另一个动画结束后开始。我正在使用动画属性并将对象定义为“AnimatorSet”。问题是第一个动画开始时没有问题,但第二个动画从未开始。

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.setTarget(ground);
moveGround.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
moveGround2.start();
}
});
moveGround.start();

(注意我们是如何先添加监听器,然后启动动画)如果这不起作用,请尝试设置一个有限的时间:moveGround.setDuration(sometime); 在启动之前检查是否有效地完成您的动画。

更新

添加 xml 文件后,我看到您有 android:repeatCount="infinite"android:repeatMode="restart",尝试删除它们或设置 android:repeatCount=0 并检查您的监听器是否已正确触发。

关于java - 动画监听器不响应 Animatorset,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32061398/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com