Android利用animation-list实现帧动画

本文实例为大家分享了利用animation-list实现帧动画的具体代码,供大家参考,具体内容如下

将要顺序播放的图片放在资源目录下

再drawable目录下新建animation1文件和animation2文件  一个是按顺序显示动画,一个是倒序显示动画,

顺序显示动画文件:animation1.xml

 
 
 
   
   
   
   
   
   
 

倒序显示动画文件:animation2.xml

 
 
 
   
   
   
   
   
   
 

布局文件

 
 
   
    
       
  

Activity文件

package org.shuxiang.test; 
 
import android.app.Activity; 
import android.graphics.drawable.AnimationDrawable; 
 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.view.Window; 
import android.widget.Button; 
import android.widget.ImageView; 
 
public class Activity10 extends Activity 
{ 
  private ImageView animationIV; 
  private Button buttonA, buttonB, buttonC; 
  private AnimationDrawable animationDrawable; 
  @Override 
  public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    setContentView(R.layout.test10); 
     
     
    animationIV = (ImageView) findViewById(R.id.animationIV); 
    buttonA = (Button) findViewById(R.id.buttonA); 
    buttonB = (Button) findViewById(R.id.buttonB); 
    buttonC = (Button) findViewById(R.id.buttonC); 
     
    buttonA.setOnClickListener(new OnClickListener() 
    { 
      @Override 
      public void onClick(View v) { 
        // TODO Auto-generated method stub 
        animationIV.setImageResource(R.drawable.animation1); 
        animationDrawable = (AnimationDrawable) animationIV.getDrawable(); 
        animationDrawable.start(); 
      } 
       
    });  
     
    buttonB.setOnClickListener(new OnClickListener() 
    { 
      @Override 
      public void onClick(View v) { 
        // TODO Auto-generated method stub 
        animationDrawable = (AnimationDrawable) animationIV.getDrawable(); 
        animationDrawable.stop(); 
      } 
       
    }); 
     
    buttonC.setOnClickListener(new OnClickListener() 
    { 
      @Override 
      public void onClick(View v) { 
        // TODO Auto-generated method stub 
        animationIV.setImageResource(R.drawable.animation2); 
        animationDrawable = (AnimationDrawable) animationIV.getDrawable(); 
        animationDrawable.start(); 
      }       
    });     
  } 
} 

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

你可能感兴趣的:(Android利用animation-list实现帧动画)