setFillAfter(a.getBoolean(com.android.internal.R.styleable.Animation_fillAfter, mFillAfter));
setRepeatCount(a.getInt(com.android.internal.R.styleable.Animation_repeatCount, mRepeatCount));
setRepeatMode(a.getInt(com.android.internal.R.styleable.Animation_repeatMode, RESTART));
setZAdjustment(a.getInt(com.android.internal.R.styleable.Animation_zAdjustment, ZORDER_NORMAL));
setBackgroundColor(a.getInt(com.android.internal.R.styleable.Animation_background, 0));
setDetachWallpaper(a.getBoolean(com.android.internal.R.styleable.Animation_detachWallpaper, false));
final int resID = a.getResourceId(com.android.internal.R.styleable.Animation_interpolator, 0);
a.recycle();
if (resID > 0) {
setInterpolator(context, resID);
}
ensureInterpolator();
}一个是直接调用一个叫ensureInterpolator的方法,另一个是先使用系统默认的一些style,然后,再调用ensureInterpolator,那这个方法到底做了啥呢?我们来看看:
[java]
/**
* Gurantees that this animation has an interpolator. Will use
* a AccelerateDecelerateInterpolator is nothing else was specified.
*/
protected void ensureInterpolator() {
if (mInterpolator == null) {
mInterpolator = new AccelerateDecelerateInterpolator();
}
}
/**
* Gurantees that this animation has an interpolator. Will use
* a AccelerateDecelerateInterpolator is nothing else was specified.
*/
protected void ensureInterpolator() {
if (mInterpolator == null) {
mInterpolator = new AccelerateDecelerateInterpolator();
}
} 3.2 成员属性
主要成员有:
1. mDuration:动画持续时间;
2. mStartOffset:某个动画的开始时间;(一组动画中,可以设置并发,或串行)
3. mFillEnabled,mFillBefore,mFillAfter:动画结束后是否回到初始状态,或者保持结束状态,默认是回到初始状态;
4. mRepeatCount,mRepeatMode:动画是否重复,重复次数,重复模式(从头开始,从头到尾再到头等);
5. mInterpolator:插补器,控制动画的快慢;
3.3 成员方法
动画开始方法:
[java]
public void setStartTime(long startTimeMillis) {
mStartTime = startTimeMillis;
mStarted = mEnded = false;
mCycleFlip = false;
mRepeated = 0;
mMore = true;
}
/**
* Convenience method to start the animation the first time
* {@link #getTransformation(long, Transformation)} is invoked.
*/
public void start() {
setStartTime(-1);
}
/**
* Convenience method to start the animation at the current time in
* milliseconds.
*/
public void startNow() {
setStartTime(AnimationUtils.currentAnimationTimeMillis());
}
public void setStartTime(long startTimeMillis) {
mStartTime = startTimeMillis;
mStarted = mEnded = false;
mCycleFlip = false;
mRepeated = 0;
mMore = true;
}
/**
* Convenience method to start the animation the first time
* {@link #getTransformation(long, Transformation)} is invoked.
*/
public void start() {
setStartTime(-1);
}
/**
* Convenience method to start the animation at the current time in
* milliseconds.
*/
public void startNow() {
setStartTime(AnimationUtils.currentAnimationTimeMillis());
}start与startNow的区别可能在于,一个有点延迟,一个立马开始。
Animation类中最主要的方法: getTransformation,这个方法只计算已经过了多久,然后调用之前创建的Interpolater来计算速率,并最终调用重载Animation类的applyTransformation方法来完成你想要展现的动画效果,那么我们来看看方法的实现吧:
[java]
/**
* Gets the transforma