Android view动画之旋转动画

编程入门 行业动态 更新时间:2024-10-09 04:17:11

Android view<a href=https://www.elefans.com/category/jswz/34/1769013.html style=动画之旋转动画"/>

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动画之旋转动画

本文发布于:2024-02-27 19:24:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1765947.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:动画   Android   view

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!