使用
val animator: ObjectAnimator = ObjectAnimator.ofFloat(imageView, "translationX", 1.0f, 0.3f)
animator.setDuration(345)
animator.start()
源码分析
ofFloat源码分析
public static ObjectAnimator ofFloat(Object target, String propertyName, float... values) {
ObjectAnimator anim = new ObjectAnimator(target, propertyName);
anim.setFloatValues(values);
return anim;
}



start源码分析






最终会调到Native层,Native处理完成后触发FrameDisplayEventReceiver的onVsync回调,回调中最后也会调用doFrame(long frameTimeNanos, int frame)方法

如果我们留意我们会发现frameCallback实际是AnimtionHandler中addAnimationFrameCallback传过去的
public void addAnimationFrameCallback(final AnimationFrameCallback callback, long delay) {
if (mAnimationCallbacks.size() == 0) {
getProvider().postFrameCallback(mFrameCallback);
}
}
mFrameCallback实际是
private final Choreographer.FrameCallback mFrameCallback = new Choreographer.FrameCallback() {
@Override
public void doFrame(long frameTimeNanos) {
doAnimationFrame(getProvider().getFrameTime());
if (mAnimationCallbacks.size() > 0) {
getProvider().postFrameCallback(this);
}
}
};

所以我们发现,这个实际就是一个循环
网友评论