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

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