Android Animated Vector Drawable: Change the degree of rotation at runtime

I am trying to create a vector animation for Android that contains a rotation in a vector group. Basically, if the degree of transition were constant, I would use these resources:

My VectorDrawable:

<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="64dp" android:height="64dp" android:viewportHeight="600" android:viewportWidth="600"> <group android:name="myRotationGroup" android:pivotX="300.0" android:pivotY="300.0" android:rotation="0"> <path android:name="myName" android:fillColor="#000000" android:pathData="M300,70 l 0,-70 70,70 0,0 -70,70z"/> </group> </vector> 

My AnimatedVectorDrawable:

 <animated-vector xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/my_vector_drawable" > <target android:name="myRotationGroup" android:animation="@animator/my_rotation" /> </animated-vector> 

And my ObjectAnimator:

 <objectAnimator android:duration="500" android:propertyName="rotation" android:valueFrom="0" android:valueTo="360" /> 

However, as you can see above, the final degree of rotation is set in the ObjectAnimator resource, for example, 360 °.

For my animation, how can I change this final value programmatically ? The degree of rotation needs to be calculated using some other data, so I don’t know the target value before starting the animation.

Thank you for your help!

+5
source share

All Articles