android 旋转动画


1.java代码

int pivotType = Animation.RELATIVE_TO_SELF; // 相对于自己

float pivotX = .5f; // 取自身区域在X轴上的中心点
float pivotY = .5f; // 取自身区域在Y轴上的中心点
rotateAnimation = new RotateAnimation(firstFromRoate, lastdegreen,
pivotType, pivotX, pivotType, pivotY); // 围绕自身的中心点进行旋转
firstFromRoate=lastdegreen;
rotateAnimation.setDuration(1000);
rotateAnimation.setRepeatCount(0);
rotateAnimation.setFillAfter(true);

iv_zhizhen.startAnimation(rotateAnimation);


2.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"  
       android:duration="500"  
       android:repeatCount="-1"  
       android:pivotX="50%"  
       android:pivotY="50%" />  
</set>

含义表示从0到359度开始循环旋转,0-359(若设置成360在停止时会出现停顿现象)度旋转所用时间为500ms,旋转中心距离view的左顶点为50%距离,距离view的上边缘为50%距离,即正中心,具体每个含义见下面的具体属性介绍。

Animation operatingAnim = AnimationUtils.loadAnimation(this, R.anim.tip);  
LinearInterpolator lin = new LinearInterpolator();  //匀速效果
operatingAnim.setInterpolator(lin);  
setInterpolator表示设置旋转速率。LinearInterpolator为匀速效果,Accelerateinterpolator为加速效果、DecelerateInterpolator为减速效果,具体可见下面android:interpolator的介绍。  

if (operatingAnim != null) {  
   infoOperatingIV.startAnimation(operatingAnim);  

完成时

infoOperatingIV.clearAnimation();   


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值