1.帧动画
即一张一张图片显示形成的视觉动画
示例,帧动画是在drawable下创建动画anim_rush.xml资源文件 素材下载
ImageView imageView = findViewById(R.id.iv_animate);
imageView.setImageResource(R.drawable.anim_rush);
//启动动画
AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getDrawable();
animationDrawable.start();
2.补间动画
补间动画有四种, alpha(淡入淡出),translate(位移),scale(缩放大小),rotate(旋转)。补间动画在res/anim(自己创建)文件夹下创建anim_set.xml
其中 repeatMode 和 repeatCount 放在补间动画节点中而不能放在set节点中,否则不生效。
AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(this,R.anim.anim_set);
imageSet.startAnimation(set);
3.属性动画
属性动画,顾名思义它是对于对象属性的动画。因此,所有补间动画的内容,都可以通过属性动画实现。
ObjectAnimator anim1 = ObjectAnimator.ofFloat(imageObject1, "rotation", 0f, 360f);
anim1.setDuration(5000);
anim1.start();
ObjectAnimator anim2 = ObjectAnimator.ofFloat(imageObject2, "alpha", 1.0f, 0.8f, 0.6f, 0.4f, 0.2f, 0.0f);
anim2.setDuration(5000);
anim2.start();
组合实现
ObjectAnimator anim3setRotate = ObjectAnimator.ofFloat(imageObject3, "rotation", 0f, 360f);
ObjectAnimator anim3setAlpha = ObjectAnimator.ofFloat(imageObject3, "alpha", 1.0f, 0.8f, 0.6f, 0.4f, 0.2f, 0.0f);
AnimatorSet set3 = new AnimatorSet();
set3.playTogether(anim3setAlpha,anim3setRotate);//同时播放
//set3.playSequentially(anim3setAlpha,anim3setRotate);//顺序播放
set3.setDuration(5000);
set3.start();
ValueAnimator
ValueAnimator valueAnimator = ValueAnimator.ofObject(new TypeEvaluator(), startP, endP);
其中TypeEvaluator是决定物体运动轨迹觉的。