今天在工作中遇到一个需求是一个登录页面在登录加载过程中,让上方的圆角图片旋转成一个类似进度条的效果
给图片设置一个旋转动画在anim文件夹中,代码如下:
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="800"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:repeatMode="restart"
android:toDegrees="359" >
</rotate>
接着在代码中开启动画,并设置停留在当前位置
animation = AnimationUtils.loadAnimation(this, R.anim.login_load_anim);
LinearInterpolator lin = new LinearInterpolator();
// 设置匀速
animation.setInterpolator(lin);
animation.setFillAfter(true); //停留在当前位置
avatar_rangle.setAnimation(animation);
animation.start();