Android实现ImageView的旋转动画
2015-12-29 16:53
429 查看
一、View基础动画 RotationAnimation
1、动态生成:RotateAnimation (float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
参数说明:
float fromDegrees:旋转的开始角度。
float toDegrees:旋转的结束角度。
int pivotXType:X轴的伸缩模式,可以取值为ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。
float pivotXValue:X坐标的伸缩值。
int pivotYType:Y轴的伸缩模式,可以取值为ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。
float pivotYValue:Y坐标的伸缩值。
2、使用动画文件res/anim/anim_round_rotate.xml:
二、利用属性动画实现立体的旋转动画
属性动画ObjectAnimation实现旋转,主要用到rotationX和rotationY这两个属性,没有rotationZ这个属性。
三、如何结束动画?
1、对于RotationAnimation,直接调用view.clearAnimation() 清除动画;
2、对于ObjectAnimation,则调用ObjectAnimation对象的end()方法结束。
1、动态生成:RotateAnimation (float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
参数说明:
float fromDegrees:旋转的开始角度。
float toDegrees:旋转的结束角度。
int pivotXType:X轴的伸缩模式,可以取值为ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。
float pivotXValue:X坐标的伸缩值。
int pivotYType:Y轴的伸缩模式,可以取值为ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。
float pivotYValue:Y坐标的伸缩值。
2、使用动画文件res/anim/anim_round_rotate.xml:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <rotate android:fromDegrees="0" android:toDegrees="359" <!--0~359防止卡顿--> android:pivotX="50%" <!--设置旋转中心点为控件中心--> android:pivotY="50%" android:duration="1000" android:repeatCount="-1" /> <!--设置不断旋转--> </set>3、如何给ImageView加上动画效果?
Animation circle_anim = AnimationUtils.loadAnimation(context, R.anim.ddqb_anim_round_rotate); LinearInterpolator interpolator = new LinearInterpolator(); //设置匀速旋转,在xml文件中设置会出现卡顿 circle_anim.setInterpolator(interpolator); if (circle_anim != null) { img_loading_circle.startAnimation(circle_anim); //开始动画 }
二、利用属性动画实现立体的旋转动画
属性动画ObjectAnimation实现旋转,主要用到rotationX和rotationY这两个属性,没有rotationZ这个属性。
ObjectAnimator icon_anim = ObjectAnimator.ofFloat(img_loading_icon, "rotationY", 0.0F, 359.0F);//设置Y轴的立体旋转动画</span></span>icon_anim.setRepeatCount(-1); icon_anim.setDuration(1000); icon_anim.setInterpolator(interpolator); //设置匀速旋转,不卡顿 icon_anim.start();
三、如何结束动画?
1、对于RotationAnimation,直接调用view.clearAnimation() 清除动画;
2、对于ObjectAnimation,则调用ObjectAnimation对象的end()方法结束。
相关文章推荐
- Gifski:一个跨平台的高质量 GIF 编码器
- 模仿动画的放大缩小容器
- jQuery 1.9.1源码分析系列(十五)动画处理之缓动动画核心Tween
- Android中ViewFlipper的使用及设置动画效果实例详解
- jQuery实现美观的多级动画效果菜单代码
- php判断GIF图片是否为动画的方法
- jQuery实现动画效果circle实例
- 浅析JavaScript动画
- js排序动画模拟-插入排序
- javascript+HTML5的Canvas实现Lab单车动画效果
- 基于javascript实现漂亮的页面过渡动画效果附源码下载
- js实现按钮颜色渐变动画效果
- jQuery实现连续动画效果实例分析
- jQuery实现带有洗牌效果的动画分页实例
- jquery实现先淡出再折叠收起的动画效果
- jQuery实现有动画淡出效果的二级折叠菜单代码
- jQuery使用animate创建动画用法实例
- jquery带动画效果幻灯片特效代码
- jQuery实现带动画效果的多级下拉菜单代码
- jQuery 1.9.1源码分析系列(十五)之动画处理