如何使用设计支持库 23.2 实现动画矢量绘图?

How to implement animated vector drawables using the design support library 23.2?

我见过 android 开发人员 blog that the new design support library 23.2 supports animated vector. When i searched i came across this link 实现动画矢量可绘制对象。在设计支持库 23.2 中实现动画矢量绘图的方法是否相同?有人可以帮我解决新的实施问题吗?

Here's a link to an example project on Github implementing the Support Library to make this Floating Action Button.

使用支持库与非支持库方法非常相似,因为 AnimatedVectorDrawables 的 xml 文件是相同的,objectAnimators 和静态 VectorDrawables 也是如此。

在设置项目以使用支持库时和在代码中引用 AnimatedVectorDrawables 时会出现差异。

确保您在 build.gradle 中使用的 AppCompat 版本至少为 23.2.0,不需要单独添加 VectorDrawable 和 AnimatedVectorDrawable 库:

dependencies {
...
...
compile 'com.android.support:appcompat-v7:23.2.0'
}

official anouncement blog you linked to 提供了几种不同的方法来确保 Android Studio 不会将您的 Vector Drawable 转换为 png。根据您使用的 Gradle 插件的版本,有两种不同的方法,因此您应该遵循适当的方法。

要从代码中的资源调用动画矢量:

AnimatedVectorDrawableCompat animatedVector = AnimatedVectorDrawableCompat.create(this, R.drawable.animated_vector_name);

您可以使用 .setImageDrawable(animatedVector); 方法在 ImageView、按钮等上显示它​​,并使用 animatedVector.start();

启动动画

重要说明:如 Chris Banes' post, there are some limitations to what will work in the support library. The sqisland.com post 中所述,您链接到包括路径变形的示例,它不适用于当前的支持库(版本 23.2.0)