android动画实现-Frame animation(一)

来源:互联网 发布:java守护线程有什么用 编辑:程序博客网 时间:2024/05/22 14:13

不说别的,直接做

第一步:创建一个动画文件

<?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: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();
   }
  });
       
    }
}

 

原创粉丝点击