view 播放动画

1.首先可以使用EasyGifAnimator,将gif文件打散

2.制作动画文件 res/anim/***_animator.xml

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false" >

    <item
        android:drawable="@drawable/lv_icon0"
        android:duration="100"/>
    
     <item
        android:drawable="@drawable/lv_icon1"
        android:duration="100"/>

</animation-list>

3.布局文件

注意:android:background="@anim/donkey_animation"

<ImageView
        android:id="@+id/pull_to_refresh_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="30dip"
        android:layout_marginRight="20dip"
        android:visibility="gone"
        android:layout_gravity="center"
        android:gravity="center"
        android:background="@anim/donkey_animation"
        />

4.代码中播放

private void playAnimation()
 {
      	
        Object ob = imageView.getBackground();
        AnimationDrawable anim = (AnimationDrawable) ob;
        anim.start();
       
 }

相关推荐