【发布时间】:2016-02-29 03:51:02
【问题描述】:
我看到android 开发者blog 说新的设计支持库23.2 支持动画矢量。当我搜索时,我遇到了这个link 来实现动画矢量绘图。在设计支持库 23.2 中实现动画矢量绘图的方法是否相同?有人可以帮我完成新的实施吗?
【问题讨论】:
标签: android animation android-studio androiddesignsupport android-vectordrawable
我看到android 开发者blog 说新的设计支持库23.2 支持动画矢量。当我搜索时,我遇到了这个link 来实现动画矢量绘图。在设计支持库 23.2 中实现动画矢量绘图的方法是否相同?有人可以帮我完成新的实施吗?
【问题讨论】:
标签: android animation android-studio androiddesignsupport android-vectordrawable
使用支持库与非支持库方法非常相似,因为 AnimatedVectorDrawables 的 xml 文件是相同的,objectAnimators 和静态 VectorDrawables 也是如此。
将项目设置为使用支持库和在代码中引用 AnimatedVectorDrawables 时会有所不同。
确保您在 build.gradle 中使用至少 23.2.0 版本的 AppCompat,不需要单独添加 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、Button 等上显示它,并使用 animatedVector.start(); 启动动画
重要提示:如Chris Banes' post 中所述,支持库中的工作存在一些限制。您链接到的sqisland.com post 包含路径变形的示例,它不适用于当前的支持库(版本 23.2.0)
【讨论】: