在请求数据返回之前,为了减少用户等待的焦虑感,经常需要有转圈加载等待的过渡效果。
加载转圈动画效果如下(录屏软件有点问题,忽略上面部分,只看下面部分的转圈动画):
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();