When I changed code line android:propertyName="scaleX"
to android:propertyName="alpha"
, animation is not working!
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>
If you want to add fade animation to your android, you can use this xml code.
This code makes the alpha value go from 0 to 1.0 in 2000ms.
Don't forget to add this in your res/anim folder and add this to your Activity.java
This should solve it.
Happy Coding.