android 實現按鈕旋轉720°

 

定義一個按鈕佈局:背景直接可以用一個圓圈加載圖片。

        <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了。到此你的按鈕就可以旋轉了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章