1.单一动画 旋转
//给铲子加动画 旋转 RotateAnimation rotateAnimation = new RotateAnimation(-10, 20, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f); rotateAnimation.setDuration(1000); rotateAnimation.setRepeatCount(Animation.INFINITE); rotateAnimation.setRepeatMode(Animation.REVERSE); img_shove.setAnimation(rotateAnimation); rotateAnimation.start();
2.组合动画 旋转 + 渐变
//给钻石加动画 旋转+渐变 RotateAnimation rotateAnimation1 = new RotateAnimation(2, -5, Animation.RELATIVE_TO_PARENT, -0.2f, Animation.RELATIVE_TO_PARENT, 0.5f); rotateAnimation1.setRepeatCount(Animation.INFINITE); rotateAnimation1.setRepeatMode(Animation.RESTART); AlphaAnimation alphaAnimation = new AlphaAnimation(0.7f, 0.0f); alphaAnimation.setRepeatCount(Animation.INFINITE); alphaAnimation.setRepeatMode(Animation.RESTART); AnimationSet animationSet = new AnimationSet(true); animationSet.setFillAfter(true); animationSet.setDuration(2000); animationSet.setStartTime(600); animationSet.addAnimation(rotateAnimation1); animationSet.addAnimation(alphaAnimation); img_shove_diamonds.startAnimation(animationSet);