动画之旋转动画"/>
Android view动画之旋转动画
本例效果:旋转360° 。
对,就是转一圈而已。
方法一
用 AnimationUtils 和 xml 的方式,加载指定的旋转动画。
Animation rotateAnimation = AnimationUtils.loadAnimation(mContext, R.anim.rotate_animation);
rotateAnimation.setFillAfter(true);
mImageView.startAnimation(rotateAnimation);
rotate_animation.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="" ><!--android:fromDegreesFloat. 旋转初始的角度。android:toDegreesFloat. 旋转结束的角度。android:pivotXFloat or percentage. 旋转中心点x坐标,表示形式有三种:1 相对于自己的左边界的距离,单位像素值。(例如 "5")2 相对于自己的左边界的距离与自身宽度的百分比。(例如 "5%")3 相对于父View的左边界的距离与父View宽度的百分比。(例如 "5%p")android:pivotYFloat or percentage. 旋转中心点y坐标,表示形式有三种:1 相对于自己的上边界的距离,单位像素值。(例如 "5")2 相对于自己的上边界的距离与自身宽度的百分比。(例如 "5%")3 相对于父View的上边界的距离与父View高度的百分比。(例如 "5%p")--><rotateandroid:duration="1000"android:fromDegrees="0"android:interpolator="@android:anim/accelerate_decelerate_interpolator"android:pivotX="50%"android:pivotY="50%"android:toDegrees="+360" />
</set>
方法二
直接代码设置
意思是:
从 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 view动画之旋转动画
发布评论