<ImageButton
android:id="@+id/btn"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="@null"
android:scaleType="fitXY"
android:src="@drawable/icon"/>
ImageButton imageBtn = (ImageButton) findViewById(R.id.btn);
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:fromDegrees="0"
android:toDegrees="359"
android:duration="300"
android:repeatCount="-1"
android:pivotX="50%"
android:pivotY="50%"
android:interpolator="@android:anim/linear_interpolator"
/>
</set>
设置补间动画变化率
Animation btnAnim = AnimationUtils.loadAnimation(this, R.anim.rotate);
LinearInterpolator linear = new LinearInterpolator();
btnAnim.setInterpolator(linear);
根据参数:上面的动画即表示以按钮的中心位置由0的位置开始,顺时针进行359度的旋转。这里的旋转可以使用下面公式求得:
旋转速度 = android:duration/(android:toDegrees-android:fromDegrees)
# 开始旋转
if (btnAnim != null) {
imageBtn.startAnimation(btnAnim);
}
# 停止旋转
imageBtn.clearAnimation();
-完-