如何使用设计支持库 23.2 实现动画矢量绘图? [英] How to implement animated vector drawables using the design support library 23.2?

查看:19
本文介绍了如何使用设计支持库 23.2 实现动画矢量绘图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过安卓开发者

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

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

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

依赖项{......编译'com.android.support:appcompat-v7:23.2.0'}

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

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

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

您可以使用 .setImageDrawable(animatedVector); 方法在 ImageViews、Buttons 等上显示它​​,并使用 animatedVector.start(); 开始动画>

重要说明:如 Chris Banes 中所述' post,支持库中的内容有一些限制.您链接到的 sqisland.com 帖子 包括路径示例变形,不适用于当前的支持库(版本 23.2.0)

I've seen the android developers blog that the new design support library 23.2 supports animated vector. When i searched i came across this link to implement animated vector drawable. Is it the same way to implement animated vector drawables in design support library 23.2? Can someone help me out with the new implementation?

解决方案

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

Using the Support Library is very similar to the non-Support Library method in that the xml files for AnimatedVectorDrawables are the same, as are the objectAnimators and static VectorDrawables.

The differences come when setting up your project to use the Support Library and when referring to the AnimatedVectorDrawables in your code.

Make sure you are using at least version 23.2.0 of AppCompat in your build.gradle, the VectorDrawable and AnimatedVectorDrawable libraries do not need to be added separately:

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

The official anouncement blog you linked to gives a couple of different ways to ensure Android Studio does not convert your Vector Drawables into pngs. There are two different methods depending on what version of the Gradle plugin you are using, so you should follow the appropriate one.

To call up an Animated Vector from resources in your code:

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

You can display this on ImageViews, Buttons etc. with their .setImageDrawable(animatedVector); method, and start the animation using animatedVector.start();

Important note: as mentioned in Chris Banes' post, there are some limitations to what will work in the support library. The sqisland.com post you linked to includes examples of Path Morphing, which won't work with the current support library(version 23.2.0)

这篇关于如何使用设计支持库 23.2 实现动画矢量绘图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆