1. 程式人生 > >Android 動畫標籤——set

Android 動畫標籤——set

作用:動畫合集

檔案目錄:res/anim/my_set.xml

<?xml version="1.0" encoding="utf-8"?>
<scale
    android:duration="2000"
    android:fromXScale="0.0"
    android:fromYScale="0.0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:repeatCount="5"
    android:toXScale="1.4"
    android:toYScale="1.4" />

<rotate
    android:duration="1000"
    android:fromDegrees="0"
    android:interpolator="@android:anim/linear_interpolator"
    android:pivotX="50%"
    android:pivotY="50%"
    android:repeatCount="infinite"
    android:toDegrees="360" />

<translate
    android:fromXDelta="0"
    android:toXDelta="-80"
    android:fromYDelta="0"
    android:toYDelta="-80"
    android:duration="2000"
    android:fillBefore="true"/>

Java程式碼: AnimationSet set = (AnimationSet ) AnimationUtils.loadAnimation(this,R.anim.my_set); imageView.startAnimation(set);

純程式碼使用:(AnimationSet) RotateAnimation rotateAnimation = new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); rotateAnimation.setFillAfter(true);// 設定保持動畫最後的狀態   rotateAnimation.setDuration(3000);// 設定動畫時間   rotateAnimation.setRepeatCount(-1);//設定重複次數 imageView.startAnimation(rotateAnimation);

TranslateAnimation translateAnimation = new TranslateAnimation(0, 0, 0, 800); translateAnimation.setRepeatCount(-1);//設定重複次數 imageView.startAnimation(translateAnimation);

AnimationSet animationSet = new AnimationSet(true); animationSet.addAnimation(rotateAnimation); animationSet.addAnimation(translateAnimation); imageView.startAnimation(animationSet);

也可以單個寫,方法設定都一樣。