How Do I Use Transparency with Transition Drawables?

663 Views Asked by At

I want to set up a transition to go from a picture/color to fully transparent. Yet no matter what I do, transparency in the transition is ignored. Here are some things I've tried:

<?xml version="1.0" encoding="UTF-8"?>
<transition xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- START STATE -->
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@color/white" />
        </shape>
    </item> 

    <!-- END STATE -->
    <item android:drawable="@drawable/rectangle_clear" />       
</transition>

where the end state is set by

<shape      xmlns:android="http://schemas.android.com/apk/res/android"

    android:shape="rectangle">

    <solid android:color="#00000000" /> <!-- I've also tried @null -->

</shape>

and I've tried:

<?xml version="1.0" encoding="UTF-8"?>
<transition xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- START STATE -->
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@color/white" />
        </shape>
    </item> 

    <!-- END STATE -->
    <item android:color="#00000000" />      <!-- I've also tried @null -->
</transition>

If I use a color like "CCFF00FF" for the end state it will ignore the "CC" (transparency) part and simply draw solid magenta. If I use "00" for alpha, it doesn't draw anything at all and simply keeps it in the start state.

How can I get it to transition to transparency?

1

There are 1 best solutions below

0
automatik On
ViewCompat.Animate(mDrawable).alpha(0.0f).setInterpolator(new FastOutSlowInInterpolator()).withLayer().setListener(null).start();

or

Animation animFadeOut = AnimationUtils.loadAnimation(this, R.anim.fade_out);
mDrawable.startAnimation(animFadeOut);

anim\fade_out.xml

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

    <alpha
        android:duration="200"
        android:fromAlpha="1.0"
        android:toAlpha="0.0" >
    </alpha>

</set>