如何用Android animated-vector实现矢量图动画XML?
- 内容介绍
- 相关推荐
本文共计900个文字,预计阅读时间需要4分钟。
基本原因通常是AnimatedVectorDrawable没有被正确启动,或者目标VectorDrawable的name和动画定义不匹配。Android不会自动播放animated-vector,必须手动调用start()方法;并且它依赖于底层矢量图中的每个path元素。
- 检查是否在代码中调用了
drawable.start()(不是invalidate()或setAlpha()) - 确认矢量图 XML 中所有被动画控制的元素都有
android:name="xxx",比如<path android:name="arrow_path" ...> - 确认 animator XML 中
android:target="arrow_path"和上面 name 严格匹配 - 避免在
app:src里直接设animated-vector—— 它不支持 layout 中自动启动,必须用app:srcCompat+ 代码启动
vector drawable 中 group 和 path 的 name 冲突问题
同一个 VectorDrawable 里,android:name 必须全局唯一。
本文共计900个文字,预计阅读时间需要4分钟。
基本原因通常是AnimatedVectorDrawable没有被正确启动,或者目标VectorDrawable的name和动画定义不匹配。Android不会自动播放animated-vector,必须手动调用start()方法;并且它依赖于底层矢量图中的每个path元素。
- 检查是否在代码中调用了
drawable.start()(不是invalidate()或setAlpha()) - 确认矢量图 XML 中所有被动画控制的元素都有
android:name="xxx",比如<path android:name="arrow_path" ...> - 确认 animator XML 中
android:target="arrow_path"和上面 name 严格匹配 - 避免在
app:src里直接设animated-vector—— 它不支持 layout 中自动启动,必须用app:srcCompat+ 代码启动
vector drawable 中 group 和 path 的 name 冲突问题
同一个 VectorDrawable 里,android:name 必须全局唯一。

