【问题标题】:dynamic VectorDrawable animation in Java instead of animated vector drawableJava中的动态VectorDrawable动画而不是动画矢量drawable
【发布时间】:2018-05-15 12:18:11
【问题描述】:

我一直在使用 xml 中的 animated-vector 来为我的一些向量设置动画,方法是使用 trimPathEnd 等,例如:

<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>

但是我想知道是否可以在不使用动画的情况下进行 trimPathEnd 或 trimPathStart,这是因为我想实现一个布局,其中基于屏幕触摸偏移量绘制矢量,所以我猜想像vector.setTrimPathEnd(0.2f); 这样我需要根据特定的偏移量动态更改Java 中的路径结束。我能找到的所有信息都是通过animated-vector 完成此操作,这不是我需要的行为。

【问题讨论】:

  • 欢迎投反对票以添加评论,也许我遗漏了什么。

标签: java android android-vectordrawable animatedvectordrawable


【解决方案1】:

Lottie 文档是这样说的:

Lottie 与 AnimatedVectorDrawable 的优点

  • 支持更多的 After Effects 功能。
  • 手动设置进度以将动画连接到手势、事件等。> - 从网络下载动画。
  • 动态播放速度。
  • 蒙版已消除锯齿。
  • 动态更改动画特定部分的颜色

它提到的是Lottie 可以Manually set progress 而AVD 不能。我找不到任何关于此的 Android 官方文档,但我相信这是真的,因为如果您查看 AnimatedVectorDrawable 代码,没有任何方法可以让您获取或设置动画进度。

所以考虑改用Lottie,许多很酷的功能和一大堆community resources

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-15
    • 1970-01-01
    相关资源
    最近更新 更多