简体   繁体   中英

dynamic VectorDrawable animation in Java instead of animated vector drawable

I have been using the animated-vector in xml to animate some of my vectors by using trimPathEnd etc with something like this for example :

<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
 android:drawable="@drawable/vectordrawable" >
  <target android:name="main_path">
<aapt:attr name="android:animation">
  <objectAnimator
    android:duration="1000"
    android:interpolator="@android:interpolator/fast_out_linear_in"
    android:propertyName="trimPathEnd"
    android:valueFrom="0"
    android:valueTo="1"/>
</aapt:attr>
</target>
</animated-vector>

However I would like to know if it is possible to trimPathEnd or trimPathStart without having to use an animation, this is because I would like to achieve a layout where the vector gets drawn based on a screen touch offset, so I guess something like vector.setTrimPathEnd(0.2f); is what I would need to dynamically change the path end in Java based on a specific offset. All the info I could find was to get this done via an animated-vector which is not the behavior I need here.

Here is what Lottie document says:

Pros of Lottie vs AnimatedVectorDrawable

  • Supports a much larger set of After Effects features.
  • Manually set progress to hook up an animation to a gesture, event, etc. > - Download animations from the network.
  • Dynamic playback speed.
  • Masks are anti-aliased.
  • Dynamically change the color of a specific part of an animations

What it mentions is Lottie can Manually set progress and AVD cannot. I can't find any Android official document for this but I believe it's true because if you look at the AnimatedVectorDrawable code, no method allows you to get or set the animation progress.

So consider using Lottie instead, many cool features and a whole bunch of community resources

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM