invalidate() 与 postInvalidate()看完这篇文章恍然大悟

作用都是重绘界面

贴上源码

invalidate()

在UI线程调用

/**
     * Invalidate the whole view. If the view is visible,
     * {@link #onDraw(android.graphics.Canvas)} will be called at some point in
     * the future.
     * 

* This must be called from a UI thread. To call from a non-UI thread, call * {@link #postInvalidate()}. */ public void invalidate() { invalidate(true); }

postInvalidate()

在非UI线程调用, 查看源码会发现, 底层也是通过调用invalidate()方法来实现重绘UI的

/**
     * 

Cause an invalidate to happen on a subsequent cycle through the event loop. * Use this to invalidate the View from a non-UI thread.

* *

This method can be invoked from outside of the UI thread * only when this View is attached to a window.

* * @see #invalidate() * @see #postInvalidateDelayed(long) */ public void postInvalidate() { postInvalidateDelayed(0); }

你可能感兴趣的:(invalidate() 与 postInvalidate()看完这篇文章恍然大悟)