Tween動畫通過對View的內容完成一系列的圖形變換,通過平移、縮放、旋轉、改變透明度來實現動畫效果。以我的理解有點像flash裏面的補間動畫。
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
<!--
這是大框架,向裏面添加內容即可完成相應的動畫
其中,alpha標籤是透明度動畫,rotate是旋轉動畫,scale是漸變尺寸伸縮動畫,translate是平移動畫
-->
<alpha
android:fromAlpha="0.1"
android:toAlpha="1.0"
android:duration="3000"
/>
<!--
3秒透明度動畫,不透明度從10% 變爲100%(即10%可見到100%可見)
-->
<rotate
android:fromDegrees="0"
android:toDegrees="359"
android:duration="1000"
android:repeatCount="infinite"
android:pivotX="50%"
android:pivotY="50%"
android:repeatMode="restart"/>
<!--
repeatMode:重複方式,有2種,
旋轉動畫,從0度到359度的旋轉,耗時1000ms(1秒),
repeatCount:循環次數,可以寫具體int值
pivotX 和 pivotY表示旋轉圓心爲物件X和Y個一半的地方,即正中心
restart表示從頭來過
reverse表示逆序
-->
</set>
在java代碼中這樣調用即可:
ImageView mImageView = (ImageView) super.findViewById(R.id.XXXX);
Animation operatingAnim = AnimationUtils.loadAnimation(this, R.anim.tip); //tip爲剛纔動畫xml文件的文件名
LinearInterpolator lin = new LinearInterpolator();
operatingAnim.setInterpolator(lin);
mImageView.setAnimation(operatingAnim);
//開始動畫
mImageView.startAnimation(operatingAnim);
//結束動畫
mImageView.clearAnimation();