postinvalidate源码分析
view中
public void postInvalidate() { postInvalidateDelayed(0); }
public void postInvalidateDelayed(long delayMilliseconds) { // 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.dispatchInvalidateDelayed(this, delayMilliseconds); } }
public void dispatchInvalidateDelayed(View view, long delayMilliseconds) { Message msg = mHandler.obtainMessage(MSG_INVALIDATE, view); mHandler.sendMessageDelayed(msg, delayMilliseconds); }
switch (msg.what) {
case MSG_INVALIDATE:
((View) msg.obj).invalidate();
break;
其他的和invalidate一样,着我们就可以看到了,postinvalidate在主线程和非主线程中都可以调用,但是Invalidate不能直接在线程中调用
作者:Peakmain
链接: https://www.jianshu.com/p/6c5d65009ba1