定義一個按鈕佈局:背景直接可以用一個圓圈加載圖片。
<Button
android:id="@+id/refresh_button"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginRight="15dp"
android:background="@mipmap/rotate" />
在代碼中找到這個按鈕後,在按鈕的事件中寫下以下方法:
final RotateAnimation animation = new RotateAnimation(0.0f, 720.0f,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
animation.setDuration(1500);
refresh_button.startAnimation(animation);
OK了。到此你的按鈕就可以旋轉了。