1.XML文件中:
\res\anim\anim_rotate_refresh.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:duration="1000"
android:fromDegrees="0"
android:interpolator="@android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:repeatMode="restart"
android:toDegrees="360"/>
</set>
2.Java文件中使用:
private ImageView mRefresh;
private Animation mRefreshAnim;
mRefresh = (ImageView) findViewById(R.id.search_refresh);
mRefreshAnim = AnimationUtils.loadAnimation(mContext, R.anim.anim_rotate_refresh);
public void stopAnim() {
mRefreshAnim.reset();
mRefresh.clearAnimation();
mRefresh.setBackgroundResource(R.drawable.search);
}
public void startAnim() {
mRefreshAnim.reset();
mRefresh.clearAnimation();
mRefresh.setBackgroundResource(R.drawable.search_refresh);
mRefresh.startAnimation(mRefreshAnim);
}