Android view动画之旋转动画

本例效果:旋转360° 。
对,就是转一圈而已。

方法一

用 AnimationUtils 和 xml 的方式,加载指定的旋转动画。

Animation rotateAnimation = AnimationUtils.loadAnimation(mContext, R.anim.rotate_animation);
rotateAnimation.setFillAfter(true);
mImageView.startAnimation(rotateAnimation);

rotate_animation.xml




    

    

方法二

直接代码设置
意思是:
从 0° 转到 360° ,旋转的中心点坐标是图片中心;
保持旋转后的状态;
旋转动画时长 1000 毫秒。

RotateAnimation rotateAnimation1 = new RotateAnimation(0,360, mImageView.getWidth()/2, mImageView.getHeight()/2);
rotateAnimation1.setFillAfter(true);
rotateAnimation1.setDuration(1000);
mImageView.startAnimation(rotateAnimation1);

方法三

属性动画实现,

//利用ObjectAnimator实现旋转动画
mImageView.setPivotX(mImageView.getWidth() / 2);
mImageView.setPivotY(mImageView.getHeight() / 2);
ObjectAnimator.ofFloat(mImageView, "rotation", 0, 360).setDuration(1000).start();

你可能感兴趣的:(Android,android,动画)