android animation rotate 圖片無限循環旋轉

須要保持界面風格一致,告訴用戶正在加載,用animation實現,很簡單 java

 

 

<set xmlns:android="http://schemas.android.com/apk/res/android"> android

    <rotate 動畫

            android:interpolator="@android :anim/cycle_interpolator" this

            android:pivotX="50%" spa

            android:pivotY="50%" .net

            android:fromDegrees="0" rest

            android:toDegrees="+360" xml

            android:duration="2000" get

            android:repeatMode="restart" animation

            android:repeatCount="-1"/>

 

</set>

 

設置上兩個參數

repeatMode 開啓循環模式

repeatCount 設置爲-1時表示無限循環

注意:上面xml中定義interpolator會出現轉一圈後停頓一下。這個時候我查到了Android中有這麼一個類LinearInerpolator:這個類是Inerpolator的子類,是實現勻速動畫的關鍵。可是不能經過XML中的那個android:interpolator屬性去設置,必須在java代碼中去實現:

Animation animation = AnimationUtils.loadAnimation(this, R.anim.rotate_loading_anim); animation.setInterpolator(new LinearInterpolator());

相關文章
相關標籤/搜索