View的measure方法會調用本身的onMeasure方法。View要在onMeasure中計算本身的大小,並將結果經過調用setMeasuredDimension(int width, int height)來保存結果。同時也要調用子View的measure方法要求子View去計算本身的大小。get
調用子View的measure方法時傳的參數要根據當前onMeasure接收的參數和子View的layout_width、layout_height屬性。io
當layout_width屬性是wrap_content時應該傳AT_MOST和從onMeasure方法獲得的width。方法
當layout_width屬性是match_parent時應該傳EXACTLY和從onMeasure方法獲得的width。im
當layout_width屬性是固定值時應該傳EXACTLY和layout_width對應的固定值(若是該固定值超過從onMeasure方法獲得的width則傳後者)。
計算結果能夠經過getMeasuredWidth()和getMeasuredHeight()獲取。
當一個控件的Layout方法被調用後geiWidth和getHeight 方法返回值纔不會是0。
View的layout方法會被父View調用。
View的layout方法會調用本身的onLayout方法。
View要在onLayout方法中調用子View的layout方法去放置子View。layout