android动画实现-Frame animation(二)

来源:互联网 发布:淘宝卖家跑哪去了 编辑:程序博客网 时间:2024/05/16 10:18

第一步:创建动画文件animation_1

<?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/aa1" android:duration="60" />
 <item android:drawable="@drawable/aa2" android:duration="60" />
 <item android:drawable="@drawable/aa3" android:duration="60" />
 <item android:drawable="@drawable/aa4" android:duration="60" />

</animation-list>

第二步:布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />
<ImageView
 android:id="@+id/im"
 android:background="@anim/animation_1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    />
</LinearLayout>

 

第三步:测试

public class AnimationTestActivity extends Activity {
    private ImageView im=null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        im=(ImageView)findViewById(R.id.im);
        //im.setBackgroundResource(R.anim.animation_1);
        final AnimationDrawable ad= (AnimationDrawable)im.getBackground();
        im.setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    ad.start();
   }
  });    
    }
}