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

Nee*_*raj 6 animation android android-studio androiddesignsupport android-vectordrawable

我见过android开发者博客,新的设计支持库23.2支持动画矢量.当我搜索时,我遇到了这个链接来实现动画矢量drawable.在设计支持库23.2中实现动画矢量drawables的方法是否相同?有人可以帮我解决新的实施问题吗?

Lew*_*ary 19

这是一个指向Github上的示例项目的链接,该项目实现了支持库以生成此浮动操作按钮.

在此输入图像描述

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

设置项目以使用支持库以及在代码中引用AnimatedVectorDrawable时,会出现差异.

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

dependencies {
...
...
compile 'com.android.support:appcompat-v7:23.2.0'
}
Run Code Online (Sandbox Code Playgroud)

您链接到的官方声明博客提供了几种不同的方法来确保Android Studio不会将您的Vector Drawable转换为png.根据您使用的Gradle插件的版本,有两种不同的方法,因此您应该遵循相应的方法.

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

AnimatedVectorDrawableCompat animatedVector = AnimatedVectorDrawableCompat.create(this, R.drawable.animated_vector_name);
Run Code Online (Sandbox Code Playgroud)

您可以使用他们的.setImageDrawable(animatedVector);方法在ImageViews,Buttons等上显示它,并使用启动动画animatedVector.start();

重要提示:正如Chris Banes的帖子所述,支持库中的工作方式存在一些限制.您链接到的sqisland.com帖子包含Path Morphing的示例,它不适用于当前的支持库(版本23.2.0)