Animation的分類
1.scaleAnimation
2.alphaAnimation
3.translateAnimation
4.rotateAnimation
5.animationSet
設(shè)置動畫開始
public void start()
設(shè)置動畫持續(xù)時間
public void setDuration(long durationMillis)
設(shè)置動畫延遲開始
public void setStartOffset(long startOffset)
設(shè)置動畫重復(fù)次數(shù)
public void setRepeatCount(int repeatCount)
設(shè)置動畫結(jié)束時候歸0
public void setFillBefore(boolean fillBefore)
設(shè)置動畫結(jié)束不歸0
public void setFillAfter(boolean fillAfter)
設(shè)置動畫的監(jiān)聽
public void setAnimationListener(AnimationListener listener)
public static interface AnimationListener {
/**
* <p>Notifies the start of the animation.</p>
*
* @param animation The started animation.
*/
void onAnimationStart(Animation animation);
/**
* <p>Notifies the end of the animation. This callback is not invoked
* for animations with repeat count set to INFINITE.</p>
*
* @param animation The animation which reached its end.
*/
void onAnimationEnd(Animation animation);
/**
* <p>Notifies the repetition of the animation.</p>
*
* @param animation The animation which was repeated.
*/
void onAnimationRepeat(Animation animation);
}
設(shè)置動畫的速率等比如線性 開始快 結(jié)束慢等
public void setInterpolator(Interpolator i)
動畫常見參數(shù)
public ScaleAnimation(float fromX, float toX, float fromY, float toY,
int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
剛開始的比例 結(jié)束的比例
pivotXType:
Animation.ABSOLUTE,
Animation.RELATIVE_TO_SELF, or
* Animation.RELATIVE_TO_PARENT.
后4個參數(shù)確定錨點
從xml文件中加載動畫
Animation loadAnimation = AnimationUtils.loadAnimation(this, R.anim.myscale);
findViewById.setAnimation(loadAnimation);
<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="2"
android:toXScale="1"
android:fromYScale="2"
android:toYScale="1"
android:pivotX="0.5"
android:pivotY="0.5"
android:duration="5000"
>
</scale>
絕對是 100
相對自己是 100%
相對父親是100%p
設(shè)置animationset的時候如果想第二個動畫開始的時候是第一個動畫結(jié)束的時間那么需要設(shè)置第二個動畫的延遲時間