/**
* <p>Cause an invalidate to happen on the next animation time step, typically the
* next display frame.</p>
*
* <p>This method can be invoked from outside of the UI thread
* only when this View is attached to a window.</p>
*
* @see #invalidate()
*/
public void postInvalidateOnAnimation() {
// We try only with the AttachInfo because there's no point in invalidating
// if we are not attached to our window
final AttachInfo attachInfo = mAttachInfo;
if (attachInfo != null) {
attachInfo.mViewRootImpl.dispatchInvalidateOnAnimation(this);
}
}
如同注释所讲,会在下一个Frame开始的时候,发起一些invalidate操作,
ViewRootImpl的dispatchInvalidateOnAnimation():
public void dispatchInvalidateOnAnimation(View view) {
mInvalidateOnAnimationRunnable.addView(view);
}
mInvalidateOnAnimationRunnable 是一个 InvalidateOnAnimationRunnable:
public void addView(View view) {
synchronized (this) {
mViews.add(view);
postIfNeededLocked();
}
}
而postIfNeededLocked()干的事情就是把mInvalidateOnAni