【发布时间】:2018-08-30 21:19:25
【问题描述】:
使用 AnimatedVectorDrawables,可以将某些动画应用到 vectordrawable 的某些部分(参见here)。例如考虑vectordrawable,称为vectordrawable.xml:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="64dp"
android:width="64dp"
android:viewportHeight="600"
android:viewportWidth="600" >
<path
android:name="path"
android:fillColor="#000000"
android:pathData="M300,70 l 0,-70 70,70 0,0 -70,70z" />
</vector>
这是一个包含单个路径(线)的vectordrawable。然后,所需的动画将位于一个单独的文件中,名为 animator.xml,例如:
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:duration="4000"
android:propertyName="trimPathEnd"
android:valueFrom="0"
android:valueTo="1" />
</set>
这将是显示正在绘制的线条的动画。然后这两个 xml 文件将输入到第三个 animatedvectordrawable xml 文件中:
<?xml version="1.0" encoding="utf-8"?>
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/vectordrawable">
<target
android:animation="@anim/animator"
android:name="path" />
</animated-vector>
所以问题是,如果你的 vectordrawable 路径包含大量路径,你想同时为它们制作动画怎么办?您可以长期执行此操作,并且必须为每条路径指定不同的名称,然后在您的 animatedvectordrawable 文件中使用相同的动画师来定位每条路径。但是如果你有超过 20 条路径,这将需要很长时间并且是一个混乱的解决方案。
您确实可以选择将一组路径包含在一个组中,然后以单个组为目标。但是组的动画与路径的动画不同,即不能为组设置动画 trimPathEnd,因此您不能将此动画应用于一组路径。
【问题讨论】:
标签: java android android-vectordrawable animatedvectordrawable