android invalidate和postinvalidate源码分析

从来好事天生俭,自古瓜儿苦后甜。这篇文章主要讲述android invalidate和postinvalidate源码分析相关的知识,希望能为你提供帮助。

android invalidate和postinvalidate源码分析

文章图片

android invalidate和postinvalidate源码分析

文章图片

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;

【android invalidate和postinvalidate源码分析】其他的和invalidate一样,着我们就可以看到了,postinvalidate在主线程和非主线程中都可以调用,但是Invalidate不能直接在线程中调用


作者:Peakmain
链接:https://www.jianshu.com/p/6c5d65009ba1

    推荐阅读