measuredWidth 與 width 分別對應于視圖繪制 的 measure 與 layout 階段。很重要的一點是,我們要明白,View 的寬高是由 View 本身和 parent 容器共同決定的,要知道有這個 MeasureSpec 類的存在。
比如,View 通過自身 measure() 方法向 parent 請求 100x100 的寬高,那么這個寬高就是 measuredWidth 和 measuredHeight 值。但是,在 parent 的 onLayout() 階段,通過 childview.layout() 方法只分配給 childview 50x50 的寬高。那么,這個 50x50 寬高就是 childview 實際繪制并顯示到屏幕的寬高,也就是 width 和 height 值。
如果你對自定義 View 過程很熟練的話,理解這部分內容就比較輕松一些。事實上,開發過程中,getWidth() 和 getHeight() 方法用的更多一些。