2016-02-18 39 views
7

我試圖讓動畫vectorDrawables工作,並根據http://developer.android.com/reference/android/graphics/drawable/AnimatedVectorDrawable.html做了一切,它仍然無法正常工作。AnimatedVectorDrawable不動畫

我也試着讓這個項目工作。 https://github.com/chiuki/animated-vector-drawable

有誰知道它爲什麼不動畫?

下面是我使用的文件:

AnimatedVectorDrawable

<animated-vector 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:drawable="@drawable/circle"> 
​ 
    <target 
     android:name="circle" 
     android:animation="@anim/morph_to_drop"/> 
​ 
</animated-vector> 

VectorDrawable

<?xml version="1.0" encoding="utf-8"?> 
<vector xmlns:android="http://schemas.android.com/apk/res/android" 
     android:width="80dp" 
     android:height="80dp" 
     android:viewportHeight="50" 
     android:viewportWidth="50"> 
​ 
    <path 
     android:name="circle" 
     android:fillColor="#607eff" 
     android:pathData="M15.9,0c8.776,0 15.9,7.125 15.9,15.9c0,8.776 -7.124,16.015 -15.9,16.015c-8.775,0 
-15.9,-7.239 -15.9,-16.015c0,-8.775 7.125,-15.9 15.9,-15.9Z"/> 
​ 
</vector> 

動畫(morph_to_drop)

<set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <objectAnimator 
     android:duration="1000" 
     android:propertyName="pathData" 
     android:valueFrom="M15.9,0c8.776,0 15.9,7.125 15.9,15.9c0,8.776 -7.124,16.015 -15.9,16.015c-8.775,0 
-15.9,-7.239 -15.9,-16.015c0,-8.775 7.125,-15.9 15.9,-15.9Z" 
     android:valueTo="M15.9,0c8.776,0 15.9,7.125 15.9,15.9c0,8.776 -12.626,30.167 
-15.707,30.143c-3.08,-0.024 -16.093,-21.367 -16.093,-30.143c0,-8.775 7.125,-15.9 
15.9,-15.9Z" 
     android:valueType="pathType"/> 
</set> 

主要佈局

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
​ 
    <ImageView 
     android:id="@+id/testImage" 
     android:layout_width="80dp" 
     android:layout_height="80dp" 
     android:layout_centerInParent="true" 
     android:src="@drawable/circle"/> 
​ 
</RelativeLayout> 
+0

你能發表morph_to_drop這個動畫文件嗎? – Harshad

+0

這實際上是我剛剛命名爲「動畫師」的文件 - 它現在增加了:) –

回答

13

嘗試以編程方式設置AnimatedVectorDrawable這樣的:

AnimatedVectorDrawable d = (AnimatedVectorDrawable) getDrawable(R.drawable.animated_vector); // Insert your AnimatedVectorDrawable resource identifier 
mImageView.setImageDrawable(d); 
d.start(); 

這應該做的伎倆。乾杯!

+0

這很快,它的工作原理,謝謝!我以爲它曾經工作,但沒有設置它編程,但無論如何:) –

+0

沒有爲我工作:( –