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

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

问题描述

我见过android开发人员



使用支持库与非支持库方法非常相似,因为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( animationVector); 方法,然后使用 animatedVector.start();



重要说明:如 Chris Banes的帖子中所述,支持库中的内容有一些限制。您链接到的 sqisland.com帖子包含路径示例Morphing,不适用于当前的支持库(版本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天全站免登陆