2016-08-08 35 views
1

Ich möchte einen Übergang einrichten, um von einem Bild/Farbe zu vollständig transparent zu gehen. Aber egal, was ich tue, Transparenz beim Übergang wird ignoriert. Hier sind einige Dinge, die ich versucht habe:Wie nutze ich Transparenz mit Übergangstabellen?

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

wo der Endzustand von

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

    android:shape="rectangle"> 

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

</shape> 

gesetzt ist, und ich habe versucht:

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

Wenn ich eine Farbe wie " CCFF00FF "für den Endzustand ignoriert es den" CC "(Transparenz) Teil und zeichnet einfach Magenta. Wenn ich "00" für Alpha verwende, zeichnet es überhaupt nichts und hält es einfach im Startzustand.

Wie bekomme ich es zum Übergang zu Transparenz?

+0

Ist das nicht nur eine [Fade Übergang] (https://developer.android.com /reference/android/transition/Fade.html)? – ianhanniballake

Antwort

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

oder

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>