Animation的分类
1.scaleAnimation
2.alphaAnimation
3.translateAnimation
4.rotateAnimation
5.animationSet
设置动画开始
public void start()
设置动画持续时间
public void setDuration(long durationMillis)
设置动画延迟开始
public void setStartOffset(long startOffset)
设置动画重复次数
public void setRepeatCount(int repeatCount)
设置动画结束时候归0
public void setFillBefore(boolean fillBefore)
设置动画结束不归0
public void setFillAfter(boolean fillAfter)
设置动画的监听
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);
}
设置动画的速率等比如线性 开始快 结束慢等
public void setInterpolator(Interpolator i)
动画常见参数
public ScaleAnimation(float fromX, float toX, float fromY, float toY,
int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
刚开始的比例 结束的比例
pivotXType:
Animation.ABSOLUTE,
Animation.RELATIVE_TO_SELF, or
* Animation.RELATIVE_TO_PARENT.
后4个参数确定锚点
从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
设置animationset的时候如果想第二个动画开始的时候是第一个动画结束的时间那么需要设置第二个动画的延迟时间