执行动画集串行序列以反转动画时出现问题

时间:2012-05-29 20:43:26

标签: android animation android-animation android-imageview

我想为 ImageView 创建动画,旋转图像,同时从100%缩放到0%,从不透明渐变到透明( SET 1 )然后反转动画( SET 2 )。两个动画集一个接一个地工作,但如果我把它们放在一起我看不到任何东西,因为动画集2的起始值会立即应用,即使它的子节点的startOffset设置为在动画集之后开始1已经完成。我想我已经明白 fadeAfter fadeBefore 应该用来避免在开始之前应用动画集2的起始值,但它对我不起作用。我已经尝试在SET 1中将 fadeAfter 设置为true,删除SET 2,看看它是否有效,即如果SET 1的转换在结束后持续存在,但又一次无效。那么,是否可以使用以下动画生成我想要的结果,可能使用 fadeAfter fadeBefore fillEnabled 属性?它应该与 ImageView 视图一起使用吗?

ANIMATION XML

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >

    <!-- SET 1 -->
    <set
        android:interpolator="@android:anim/decelerate_interpolator"
        android:shareInterpolator="true" >
        <alpha android:fromAlpha="1"
            android:toAlpha="0"
            android:duration="1000"
            android:startOffset="500"/>
        <rotate
            android:duration="1000"
            android:fromDegrees="0"
            android:pivotX="50%"
            android:pivotY="50%"
            android:startOffset="500"
            android:toDegrees="720" />

        <scale
            android:duration="1000"
            android:fromXScale="100%"
            android:fromYScale="100%"
            android:pivotX="50%"
            android:pivotY="50%"
            android:startOffset="500"
            android:toXScale="0%"
            android:toYScale="0%" />
    </set>

    <!-- SET 2 -->
    <set
        android:interpolator="@android:anim/accelerate_interpolator"
        android:shareInterpolator="true">
         <alpha android:fromAlpha="0"
            android:toAlpha="1"
            android:duration="1000"
            android:startOffset="1500"/>
        <rotate
            android:duration="1000"
            android:fromDegrees="0"
            android:pivotX="50%"
            android:pivotY="50%"
            android:toDegrees="720"
        android:startOffset="1500" />

        <scale
            android:duration="1000"
            android:fromXScale="0%"
            android:fromYScale="0%"
            android:pivotX="50%"
            android:pivotY="50%"
            android:toXScale="100%"
            android:toYScale="100%"
        android:startOffset="1500" />
    </set>
</set>

动画启动JAVA代码

ImageView iv = (ImageView) findViewById(R.id.image_view);
Animation animation = AnimationUtils.loadAnimation(this, R.anim.test_animation);
iv.startAnimation(animation);

使用动画重复进行测试

我还尝试删除SET 2并在 startAnimation 之前添加以下代码,但动画不会以相反的顺序重复(我也可以指定RESTART和X重复周期,它不会不行。有什么想法或建议吗?!

animation.setRepeatCount(1);
animation.setRepeatMode(Animation.REVERSE);

0 个答案:

没有答案