android two alpha animations

2019-06-09 01:58发布

I'm trying to put in two alpha animations in one AnimationSet, as follows, but when I run it, the first (fadeout) animation happens, but it remains blank for the next animation. I understand that I can use a repeatMode="reverse" to do this, but I would like to know why this is not working in case I want to do something more fancy. Thanks.

   <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android" >
        <alpha
            android:duration="1000"
            android:fillAfter="false"
            android:fromAlpha="1.0"
            android:toAlpha="0.0" />
        <alpha
            android:duration="1000"
            android:fillBefore="false"
            android:fillEnabled="true"
            android:fromAlpha="0.0"
            android:startOffset="1000"
            android:toAlpha="1.0" />
    </set>

1条回答
ら.Afraid
2楼-- · 2019-06-09 02:14

I came to this post following the same thought.And i have tested this one now. Unexpectedly its working perfect. Here goes my code.

    <alpha
        android:duration="1000"
        android:fromAlpha="0.25"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:repeatMode="reverse"
        android:startOffset="500"
        android:toAlpha="1.0" />
    <alpha
        android:duration="1000"
        android:fromAlpha="1.0"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:repeatMode="reverse"
        android:startOffset="3500"
        android:toAlpha="0.25" />

The first one will set alpha to a higher value and its pulled low after some time using a second alpha. Make sure you add "repeatMode" as "reverse" , even though repeatcount is not set and no repeat happens. And the actual flow that happens is not reversing the first alpha , but switching to the second alpha for reverse operation .

查看更多
登录 后发表回答