Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 854
Neeraj Avatar asked Feb 29 '16 03:02

Neeraj


People also ask

Does Android studio support SVG?

Android Studio includes a tool called Vector Asset Studio that helps you add material icons and import Scalable Vector Graphic (SVG) and Adobe Photoshop Document (PSD) files into your project as vector drawable resources.

What is Android SVG?

AndroidSVG is a SVG parser and renderer for Android. It has almost complete support for the static visual elements of the SVG 1.1 and SVG 1.2 Tiny specifications (except for filters).


1 Answers

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

enter image description here

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)

like image 147
Lewis McGeary Avatar answered Sep 22 '22 23:09

Lewis McGeary