一、View动画种类

Android path动画 android view动画_帧动画

1、使用View,首先要创建XML文件。 res/anim/filename.xml

Android path动画 android view动画_XML_02

2、应用动画:

//使用动画
        Button button;
        Animation animation = AnimationUtils.loadAnimation(this,R.anim.filename);
        button.startAnimation(animation);
        
        //应用动画--改变透明度
        AlphaAnimation alphaAnimation = new AlphaAnimation(0,1);
        alphaAnimation.setDuration(300);
        button.startAnimation(alphaAnimation);

二、自定义View动画

自定义动画只需要继承Animation抽象类,重写initialize/applyTransformation

public class AnimationTest extends Animation {
    //初始化工作
    @Override
    public void initialize(int width, int height, int parentWidth, int parentHeight) {
        super.initialize(width, height, parentWidth, parentHeight);
    }
    //矩阵变换
    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
        super.applyTransformation(interpolatedTime, t);
    }
}

三、帧动画

1、首先通过XML来载入一组定义好的图片

Android path动画 android view动画_帧动画_03

2、通过AnimationDrawable来使用帧动画

Button button;
        button.setBackgroundResource(R.drawable.frame_animation);//帧动画资源
        AnimationDrawable drawable = (AnimationDrawable)button.getBackground();
        drawable.start();