
SDK Manager提示支持库更新

使用Vector动画主要有三个部分: Vector图像, 路径动画, Animated-Vector图像.
本文源码的Github下载地址.
动画

1. Vector图像
SVG格式的图片, 转换为Vector图像资源, 可以使用AS2.0的转换工具, 也可以是在线转换工具, 参考. 图像需要路径(path)样式, 便于绘制, 如
<vector xmlns:android="http://schemas.android.com/apk/res/android"android:width="256dp"android:height="256dp"android:viewportHeight="70"android:viewportWidth="70"><pathandroid:name="heart1"android:pathData="..."android:strokeColor="#E91E63"android:strokeWidth="1"/><pathandroid:name="heart2"android:pathData="..."android:strokeColor="#E91E63"android:strokeWidth="1"/></vector>2. 路径动画
<?xml version="1.0" encoding="utf-8"?><objectAnimatorxmlns:android="http://schemas.android.com/apk/res/android"android:duration="6000"android:propertyName="trimPathEnd"android:valueFrom="0"android:valueTo="1"android:valueType="floatType"/>ObjectAnimator的trimPathEnd属性决定绘制path的数量, 其余部分不会绘制, 其取值区间是0到1. duration属性表示持续时间, 6000即6秒.
<animated-vectorxmlns:android="http://schemas.android.com/apk/res/android"android:drawable="@drawable/v_heard"><targetandroid:name="heart1"android:animation="@animator/heart_animator"/><targetandroid:name="heart2"android:animation="@animator/heart_animator"/>...</animated-vector>4. 显示动画
// 只支持5.0以上.private void animateImage() {if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {// 获取动画效果AnimatedVectorDrawable mAnimatedVectorDrawable = (AnimatedVectorDrawable)ContextCompat.getDrawable(getApplication(), R.drawable.v_heard_animation);mIvImageView.setImageDrawable(mAnimatedVectorDrawable);if (mAnimatedVectorDrawable != null) {mAnimatedVectorDrawable.start();}}}AnimatedVectorDrawable的start方法就是动画启动功能.