在android開發,我們會常常使用到旋轉動畫,普通情況下旋轉動畫有兩種實現方式,一種是直接通過java代碼去實現,第二種是通過配置文件實現動畫。以下是兩種動畫的基本是用法:
純Java代碼實現:
//創建旋轉動畫 Animation animation = new RotateAnimation(0, 359); animation.setDuration(500); animation.setRepeatCount(8);//動畫的反復次數 animation.setFillAfter(true);//設置為true,動畫轉化結束后被應用 imageView1.startAnimation(animation);//開始動畫
通過配置文件實現:
1、首先要在res文件夾下建立一個anim文件,在anim建立一個rotate.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:toDegrees="+360" android:repeatCount="10" android:repeatMode="restart" android:pivotX="50%" android:pivotY="50%" android:interpolator="@android:anim/overshoot_interpolator" /> </set>
2、載入動畫
Animation animation = AnimationUtils.loadAnimation(this, R.anim.rotate); imageView1.startAnimation(animation);//開始動畫
案例下載地址: http://download.csdn.net/detail/u013043346/9374204
