0

I want run alpha animation from 1 to 0 first, and after I want to run alpha animation from 0 to 1, but it doesn't work! this is my code:

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>

but when I want run alpha animation first, and after run scale animation, it works well! Below is my code:

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>

why?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Guo
  • 1,761
  • 2
  • 22
  • 45

1 Answers1

0

I have tried the following and it works for me.

<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>

I followed this. Hope this helps you.

Rozina
  • 409
  • 3
  • 14