Android 利用 xml 文件实现 ImageView 的加载转圈动画
16lz
2021-01-23
在请求数据返回之前,为了减少用户等待的焦虑感,经常需要有转圈加载等待的过渡效果。
加载转圈动画效果如下(录屏软件有点问题,忽略上面部分,只看下面部分的转圈动画):
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();
更多相关文章
- android文字阴影效果设置
- Android TextView投影效果
- android 2048游戏、kotlin应用、跑马灯、动画源码
- Android四大视图动画图文详解
- 谁说Android的动画不廉价(二)之转场动画
- android酷炫翻页效果+图形分析