2017-01-09 19 views
0

Wenn ich die Codezeile android:propertyName="scaleX" zu android:propertyName="alpha" änderte, funktioniert die Animation nicht!Android objectAnimator set propertyValuesHolder

-Code

AnimatedVectorDrawableCompat mAnimatedVectorDrawable = AnimatedVectorDrawableCompat.create(
         getApplication(), R.drawable.v_frame_animation 
       ); 
       image.setImageDrawable(mAnimatedVectorDrawable); 
       if (mAnimatedVectorDrawable != null) { 
        mAnimatedVectorDrawable.start(); 
       } 

Animator/v_frame_animation.xml

<?xml version="1.0" encoding="utf-8"?> 
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:drawable="@drawable/gears_copy"> 
     <target 
      android:name="vaaa" 
      android:animation="@animator/heart_frame_animator" /> 
    </animated-vector> 

Animator/heart_frame_animator.xml

<?xml version="1.0" encoding="utf-8"?> 
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android" 
      android:duration="5000" 
      android:repeatCount="infinite" 
      android:valueType="floatType"> 
      <propertyValuesHolder 
       android:propertyName="scaleX" 
       android:valueType="floatType"> 
       <keyframe 
        android:fraction="0" 
        android:interpolator="@android:anim/accelerate_interpolator" 
        android:value="0" /> 
       <keyframe 
        android:fraction=".5" 
        android:interpolator="@android:anim/accelerate_interpolator" 
        android:value="1" /> 
       <keyframe 
        android:fraction="1" 
        android:interpolator="@android:anim/accelerate_interpolator" 
        android:value="0" /> 
      </propertyValuesHolder> 
     </objectAnimator> 
+0

Können Sie den "fillAlpha" -Eigenschaftsnamen versuchen? – GaborNovak

Antwort

0

Wenn Sie verblassen Animation zu Ihrem Android hinzufügen möchten, können Sie Dieser XML-Code.

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android"> 
<alpha 
android:fromAlpha="0" 
android:toAlpha="1.0" 
android:duration= "2000" 
/> 
</set> 

Dieser Code bewirkt, dass der Alpha-Wert in 2000ms von 0 auf 1,0 wechselt.

Vergessen Sie nicht, dies in Ihrer res/anim Ordner hinzufügen und diese

try { 
     Animation myFadeInAnimation = AnimationUtils.loadAnimation(this, R.anim.splash); 
     splash.startAnimation(myFadeInAnimation);//splash is an ImageView 
    }catch (NullPointerException e){ 
     e.printStackTrace(); 
    } 

Dies sollte es lösen zu Ihrem Activity.java hinzuzufügen.

Glückliche Kodierung.

Verwandte Themen