自定義控制元件基礎 requestLayout()和invalidate()區別
阿新 • • 發佈:2019-02-01
requestLayout():
重新佈局整個ViewTree,開始呼叫measure()方法。
requestLayout()是view的方法,view也可以呼叫該方法。Call this when something has changed which has invalidated the layout of this view. This will schedule a layout pass of the view tree. This should not be called while the view hierarchy is currently in a layout pass.
invalidate():
如果當前View可見,onDraw()方法將會被呼叫。Invalidate the whole view. If the view is visible, onDraw() 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 postInvalidate().
在寫SimpleIndicator時,並不是一定不會走onMeasure()方法,在某種條件下會走該方法的。可以搜其他的原始碼分析文章,具體檢視。