【问题标题】:How to run two or more animation in order (one by one) in Android?如何在Android中按顺序(一个接一个)运行两个或多个动画?
【发布时间】:2018-05-18 09:44:04
【问题描述】:

我想先运行从10alpha动画,然后之后我想运行alpha 动画01,但它不起作用! 这是我的代码:

TextView iv_1 = findViewById(R.id.tv_1);
AnimationSet animSet = (AnimationSet) AnimationUtils.loadAnimation(this, R.anim.alpha_set);
iv_1.setAnimation(animSet);

alpha_set.xml

<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:fillAfter="true"
>

    <alpha android:duration="2000"
           android:fromAlpha="1"
           android:toAlpha="0"
    />

    <alpha android:duration="2000"
           android:fromAlpha="0"
           android:toAlpha="1"
           android:startOffset="2000"/>

</set>

但是当我想先运行 alpha 动画,然后运行 ​​缩放动画,它效果很好!以下是我的代码:

TextView iv_1 = findViewById(R.id.tv_1);
AnimationSet animSet = (AnimationSet) AnimationUtils.loadAnimation(this, R.anim.alpha_and_scale);
iv_1.setAnimation(animSet);

alpha_and_scale.xml

<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:fillAfter="true">

    <alpha android:duration="2000"
           android:fromAlpha="0"
           android:toAlpha="1"
    />
    <scale android:startOffset="2000"
           android:pivotX="50%"
           android:pivotY="50%"
           android:fromXScale="0.8"
           android:toXScale="1"
           android:fromYScale="1"
           android:toYScale="1"
           android:duration="2000"/>

</set>

为什么?

【问题讨论】:

  • 您可以使用动画侦听器作为解决方法。或者只是使用动画重复计数 (2) 和重复模式 (reverse) 来重复动画
  • 感谢您的帮助!但它不能解决我的问题
  • 我看不出它不能这样做的单一原因。
  • @VladyslavMatviienko 你能尝试在你的设备上运行我的代码吗?

标签: android android-animation


【解决方案1】:

我已经尝试了以下方法,它对我有用。

<set xmlns:android="http://schemas.android.com/apk/res/android">
  <alpha
    android:duration="2000"
    android:fromAlpha="1"
    android:toAlpha="0"
    android:repeatMode="reverse"
    android:repeatCount="1"/>
</set>

我关注了this.希望这对你有帮助。

【讨论】:

    猜你喜欢
    • 2015-05-12
    • 2018-08-20
    • 1970-01-01
    • 2011-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多