Peter
Peter

Reputation: 311

How can I get AnimatorSet from AnimatedVectorDrawableCompat?

I was trying to animate a vector drawable and adjust start time by using AnimatorInflater.loadAnimator and setStartDelay, but it appears to be AnimatorSet of AnimatedVectorDrawableCompat having different AnimatorSet from what I can get from AnimtorInflater.

I tried to find some sort of getter function that returns AnimatorSet, but I couldn't. I also tried android developer document.

Is there any way I can control AnimatorSet of it? or is there any other fancy way of controlling xml animators as a whole and targeting it to a vector drawable?

In MyActivity:

    AnimatorSet s = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.animaiton);  
    s.setStartDelay(2000); // not working but Somehting like this.
    AnimatedVectorDrawableCompat animatedVectorDrawableCompat = AnimatedVectorDrawableCompat.create(this, R.drawable.logo_drawable_animated);
    montiyaLogo.setImageDrawable(animatedVectorDrawableCompat);
    animatedVectorDrawableCompat = (AnimatedVectorDrawableCompat)montiyaLogo.getDrawable();
    animatedVectorDrawableCompat.start();

In res/animator/animtion.xml:

   <objectAnimator
        android:propertyName="strokeColor"
        android:startOffset="1320" //here
        android:duration="156"
        android:valueFrom="#0187ff"
        android:valueTo="#ffffff"
        android:valueType="colorType"
        android:interpolator="@android:anim/accelerate_interpolator"/>

Just in case there might be somthing I am missing.., here is my animaiton:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <objectAnimator
        android:startOffset="1000" //this is just for temporal improvisation.
        android:propertyName="trimPathEnd"
        android:duration="332"
        android:valueFrom="0"
        android:valueTo="0.999"
        android:valueType="floatType"
        android:interpolator="@android:anim/accelerate_interpolator"/>
    <objectAnimator
        android:startOffset="1000" //this is just for temporal improvisation.
        android:propertyName="strokeColor"
        android:duration="167"
        android:valueFrom="#0187ff"
        android:valueTo="#e530fe"
        android:valueType="colorType"
        android:interpolator="@android:anim/accelerate_interpolator"/>
</set>

logo_drawable_animated.xml:

<?xml version="1.0" encoding="utf-8"?>
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/logo_drawable" >
    <target
        android:name="logoPath"
        android:animation="@animator/letterm_animation" />
    <target
        android:name="logoPath2"
        android:animation="@animator/letterm_animation" />
</animated-vector>

Upvotes: 0

Views: 262

Answers (0)

Related Questions