drawable/vectordrawable.xml
    android:width="64dp"
    android:viewportHeight="600"
    android:viewportWidth="600">
    
        android:pivotX="300.0"
        android:pivotY="300.0"
        android:rotation="45.0" >
        
            android:fillColor="#000000"
            android:pathData="M300,70 l 0,-70 70,70 0,0 -70,70z" />
    
drawable/animvectordrawable.xml
    
        android:animation="@anim/rotation" />
    
        android:animation="@anim/path_morph" />
anim/rotation.xml
    android:duration="6000"
    android:propertyName="rotation"
    android:valueFrom="0"
    android:valueTo="360" />
anim/path_morph.xml
    
        android:propertyName="pathData"
        android:valueFrom="M300,70 l 0,-70 70,70 0,0   -70,70z"
        android:valueTo="M300,70 l 0,-70 70,0  0,140 -70,0 z"
        android:valueType="pathType" />
Edit layout file, layout/activity_main.xml, to include ImageViews with android:src="@drawable/animvectordrawable".
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="10dp"
    tools:context=".MainActivity">
    
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:autoLink="web"
        android:text="http://picturedmagazine.blogspot.com/"
        android:textStyle="bold" />
    
        android:layout_height="match_parent"
        android:orientation="horizontal">
        
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/animvectordrawable"
            android:background="#D0D0D0"/>
        
            android:layout_width="32dp"
            android:layout_height="32dp"
            android:src="@drawable/animvectordrawable"
            android:background="#B0B0B0"/>
        
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/animvectordrawable"
            android:background="#909090"/>
    
Edit MainActivity.java to start animation once clicked.
package com.blogspot.android_er.androidanimatedvectordrawable;
import android.app.Activity;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ImageView imageView1 = (ImageView)findViewById(R.id.imageview1);
        imageView1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Drawable drawable = ((ImageView) v).getDrawable();
                ((Animatable) drawable).start();
            }
        });
        ImageView imageView2 = (ImageView)findViewById(R.id.imageview2);
        imageView2.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                Drawable drawable = ((ImageView)v).getDrawable();
                ((Animatable) drawable).start();
            }
        });
        ImageView imageView3 = (ImageView)findViewById(R.id.imageview3);
        imageView3.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                Drawable drawable = ((ImageView)v).getDrawable();
                ((Animatable) drawable).start();
            }
        });
    }
}
Related:
- Vector Drawable example
 


 
 
0 تعليقات