Sogrey / Android_QA

https://sogrey.github.io/Android_QA/
MIT License
0 stars 0 forks source link

invalidate和postInvalidate的区别及使用 #123

Open Sogrey opened 5 years ago

Sogrey commented 5 years ago

View.invalidate(): 层层上传到父级,直到传递到ViewRootImpl后触发了scheduleTraversals(),然后整个View树开始重新按照View绘制流程进行重绘任务。

invalidate:在ui线程刷新view postInvalidate:在工作线程刷新view(底层还是handler)其实它的原理就是invalidate+handler

View.postInvalidate最终会调用ViewRootImpl.dispatchInvalidateDelayed()方法