经常看到很多应用会在ActionBar上放一个刷新按钮用来刷新页面内容。
当点击这个按钮时,按钮不断旋转,同时访问网络去刷新内容,刷新完成后,动画停止。
主要实现逻辑如下:
//这里使用一个ImageView设置成MenuItem的ActionView,这样我们就可以使用这个ImageView显示旋转动画了
ImageView refreshActionView = new ImageView(this);
refreshActionView.setImageResource(drawable.ic_action_refresh);
refreshItem.setActionView(refreshActionView);
//显示刷新动画
Animation animation = AnimationUtils.loadAnimation(this, anim.refresh);
animation.setRepeatMode(Animation.RESTART); //设置动画从头开始
animation.setRepeatCount(Animation.INFINITE);
refreshActionView.startAnimation(animation);
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:interpolator="@android:anim/linear_interpolator"
android:duration="2000"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:repeatMode="restart"
android:repeatCount="infinite"
/>
</set><set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator">
<rotate
android:duration="2000"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:repeatMode="restart"
android:repeatCount="infinite"
/>
</set>原文地址:http://blog.csdn.net/shineflowers/article/details/45483123