2016-02-18 8 views
7

アニメーション化されたvectorDrawableを動作させようとしましたが、すべてを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

私のために働いていない:( –

関連する問題