Animation-list帧动画使用【微信语音播放动画】

第一步:先上图片素材,以下素材放到res/drawable目录下:

http://blog.csdn.net/aminfo/article/details/7847761

图片素材:

文件名称:

icon1.png

icon1.png

icon1.png

icon1.png

icon1.png

icon1.png

第二步:上动画Animation-list帧布局文件,有2个,一个是按顺序显示动画,一个是倒序显示动画,文件存放在res/drawable目录下

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




  	
  	
  	
  	
  	
  	


 

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




  	
  	
  	
  	
  	
  	


第三步:上布局文件,放在res/layout目录下,文件名main.xml



   
  
      
 

第四步:上Activity文件,文件名:MainActivity.java

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


 

 

 

 

 

 

 

你可能感兴趣的:(Animation-list帧动画使用【微信语音播放动画】)