我使用动画矢量从支持库23.2.0,就像这样:
compile 'com.android.support:support-vector-drawable:23.2.0'
compile 'com.android.support:animated-vector-drawable:23.2.0'
Run Code Online (Sandbox Code Playgroud)
我试图动画" pathData "(将线条变换为另一个).我的代码看起来像这样.
绘制/ ic_done.xml:
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:name="tick"
android:pathData="M4.8,12L9,16.2L20,8"
android:strokeColor="#FF000000" />
</vector>
Run Code Online (Sandbox Code Playgroud)
绘制/ ic_done_animated.xml:
<?xml version="1.0" encoding="utf-8"?>
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:drawable="@drawable/ic_done">
<target
android:name="tick"
android:animation="@animator/tick_path_animation" />
</animated-vector>
Run Code Online (Sandbox Code Playgroud)
动画师/ tick_path_animation.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:ordering="sequentially">
<objectAnimator
android:duration="200"
android:propertyName="pathData"
android:valueFrom="M4.8,12L4.8,12L4.8,12"
android:valueTo="M4.8,12L9,16.2L9,16.2"
android:valueType="pathType" />
<objectAnimator
android:duration="200"
android:propertyName="pathData"
android:valueFrom="M4.8,12L9,16.2L9,16.2"
android:valueTo="M4.8,12L9,16.2L20,8"
android:valueType="pathType" />
</set>
Run Code Online (Sandbox Code Playgroud)
Java代码:
ImageView vImgAnimated = findByViewId(R.id.img);
AnimatedVectorDrawableCompat animatedVector = AnimatedVectorDrawableCompat.create(getContext(), R.drawable.ic_done_animated);
vImgAnimated.setImageDrawable(animatedVector);
animatedVector.start(); …Run Code Online (Sandbox Code Playgroud) java android android-animation android-support-library android-vectordrawable