三种动画方式 帧动画 属性动画 补间动画

1.帧动画 

AnimationDrawable animationDrawable = new AnimationDrawable();
//添加动画
animationDrawable.addFrame(getDrawable(R.drawable.q),100);
animationDrawable.addFrame(getDrawable(R.drawable.w),100);
animationDrawable.addFrame(getDrawable(R.drawable.e),100);
animationDrawable.addFrame(getDrawable(R.drawable.r),100);
animationDrawable.addFrame(getDrawable(R.drawable.t),100);
animationDrawable.addFrame(getDrawable(R.drawable.y),100);
animationDrawable.addFrame(getDrawable(R.drawable.u),100);
animationDrawable.addFrame(getDrawable(R.drawable.i),100);
animationDrawable.addFrame(getDrawable(R.drawable.o),100);
animationDrawable.addFrame(getDrawable(R.drawable.p),100);

animationDrawable.setOneShot(false);  //false 一直循环  
img.setImageDrawable(animationDrawable); //动画 赋给 img
animationDrawable.start(); //开始动画

2.补间动画

        ObjectAnimator alpha = ObjectAnimator.ofFloat(img, "alpha", 3, 2, 0);
        ObjectAnimator rotation = ObjectAnimator.ofFloat(img, "rotation", 0, 200);
        ObjectAnimator scaleX = ObjectAnimator.ofFloat(img, "scaleX", 1, 2);
        ObjectAnimator scaleY = ObjectAnimator.ofFloat(img, "scaleY", 1, 2);

        AnimatorSet animatorSet = new AnimatorSet();    //集合 动画
        animatorSet.setTarget(alpha);                   //往集合 添加动画
        animatorSet.setTarget(rotation);
        animatorSet.setTarget(scaleX);
        animatorSet.setTarget(scaleY);
        animatorSet.setDuration(4000);   //4秒播放完
        animatorSet.playSequentially(rotation,scaleX,scaleY,alpha); //按顺序播放动画
        animatorSet.start(); //开始动画

3.属性动画 ofFloat 三个参数  图片 动画类型  数值

        ObjectAnimator alpha = ObjectAnimator.ofFloat(img, "alpha", 3, 2, 0);   //逐渐消失 
        ObjectAnimator rotation = ObjectAnimator.ofFloat(img, "rotation", 0, 200); //旋转
        ObjectAnimator scaleX = ObjectAnimator.ofFloat(img, "scaleX", 1, 2);  //X横向 放大两倍
        ObjectAnimator scaleY = ObjectAnimator.ofFloat(img, "scaleY", 1, 2);//Y横向 放大两倍
        alpha.setDuration(3000);    
        alpha.setInterpolator(new LinearInterpolator());

    原文作者:War_mheart
    原文地址: https://blog.csdn.net/War_mheart/article/details/121288968
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞