Android 利用 xml 文件实现 ImageView 的加载转圈动画

在请求数据返回之前,为了减少用户等待的焦虑感,经常需要有转圈加载等待的过渡效果。

加载转圈动画效果如下(录屏软件有点问题,忽略上面部分,只看下面部分的转圈动画): 


这里写图片描述

 

1、在 res/anim/ 文件夹下新建anim_circle_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>  

2、给目标 ImageView(mIvRotate)加上动画效果

Animation rotateAnimation = AnimationUtils.loadAnimation(this, R.anim.anim_circle_rotate);
LinearInterpolator interpolator = new LinearInterpolator();
rotateAnimation.setInterpolator(interpolator);
mIvRotate.startAnimation(rotateAnimation);

3、结束动画 
对于Animation /RotationAnimation,直接调用View.clearAnimation()清除动画;

mIvRotate.clearAnimation();
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值