在我的 Android 应用程序中,我想在另一个 View 动画完成后在一个 View 上启动一个动画。所以我使用了AnimationListener,并使用了覆盖方法onAnimationEnd()。 但问题是当第一个 View 的动画完成时,第一个和第二个 View 都开始动画。这意味着第一个 View 用第二个动画重复它的动画。
final Animation anim = AnimationUtils.loadAnimation(Home.this,R.anim.myanimation);
anim.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
image_2.startAnimation(anim);
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}});
image_1.startAnimation(anim);
我希望 image_2 的动画在 image_1 的动画之后开始。但是 image_1 不会重复它的动画。动画将按顺序发生。如何做到这一点?
我的动画代码如下:
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator" android:fillEnabled="true" android:fillAfter="true" android:startOffset="5000">
<scale android:fromXScale="1.0" android:toXScale="0.0" android:fromYScale="1.0" android:toYScale="1.0" android:pivotX="100%" android:duration="8000" />
</set>
最佳答案
这是因为您应该需要实现两个监听器。当您最初调用 image2 动画时,动画会发生,在动画监听器结束后,动画会再次发生,因此动画将发生两次。因此,为两个 ImageView 设置两个监听器和两个单独的动画可能会解决您的问题。 .
关于Android:在实现 AnimationListener 时动画正在重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14727446/