Android动画之RotateAnimation使用

  • RotateAnimation:旋转动画,顾名思义,使用该动画,view能产生旋转效果

    比如QQ音乐播放状态的专辑


  • 看一下xml文件:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <rotate
        android:duration="5000"
        android:fillAfter="true"
        android:fromDegrees="0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:repeatMode="restart"
        android:repeatCount="infinite"
        android:toDegrees="360" />
</set>

属性解释:

android:fromDegrees=”0” //从多少度开始旋转
android:toDegrees=”360” //旋转到多少度结束
android:pivotX=”50%” // 相对x轴起始位置开始执行动画,取值(0-100%)
android:pivotY=”50%” // 相对y轴起始位置开始执行动画,取值(0-100%)
android:repeatMode=”restart” //重复模式为:重复动画
android:repeatCount=”infinite”//重复次数:无限次


  • Java代码调用xml文件:
    /**
     * 旋转动画
     *
     * @param context
     * @param view 目标view
     */
    public static void startRotateAnim(Context context, View view) {
        Animation animation = AnimationUtils.loadAnimation(context, R.anim.anim_rotate);
        animation.setInterpolator(new LinearInterpolator());
        if (view != null)
            view.startAnimation(animation);
    }
  • 效果如下:
    这里写图片描述

  • 纯Java代码动画:
   public static void animRotate(View view){
        RotateAnimation animation = new RotateAnimation(0,360f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
        animation.setDuration(5000);
        animation.setFillAfter(true);
        animation.setInterpolator(new LinearInterpolator());
        animation.setRepeatMode(Animation.RESTART);
        animation.setRepeatCount(Animation.INFINITE);
        if (view != null)
            view.startAnimation(animation);
    }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值