创建动画

来源:互联网 发布:import java 编辑:程序博客网 时间:2024/06/13 03:45

1、在布局文件里添加

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.28"
        android:background="@drawable/tupian1" />


2、在drawable-hdpi里添加tupian1


3、在mainActivity里添加代码

        imageView=(ImageView)findViewById(R.id.imageView);
        
        //创建帧动画对象
        animationDrawable=new AnimationDrawable();
        animationDrawable.addFrame(getResources().getDrawable(R.drawable.tupian1), 100);
        animationDrawable.addFrame(getResources().getDrawable(R.drawable.tupian2), 100);
        imageView.setBackground(animationDrawable);


          public void startKill(View v){
    animationDrawable.start();
    }
    public void stopKill(View v){
    if(animationDrawable.isRunning())
    animationDrawable.stop();
    }