1

我想设置从图片/颜色到完全透明的过渡。然而,无论我做什么,过渡的透明度都被忽略了。以下是我尝试过的一些事情:

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

结束状态由

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

    android:shape="rectangle">

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

</shape>

我试过了:

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

如果我使用“CCFF00FF”之类的颜色作为最终状态,它将忽略“CC”(透明度)部分并简单地绘制纯洋红色。如果我对 alpha 使用“00”,它根本不会绘制任何东西,只是将其保持在开始状态。

我怎样才能让它过渡到透明度?

4

1 回答 1

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

或者

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

动画\淡出.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>
于 2016-08-08T23:22:35.523 回答