android.view.ViewGroup
protected void onLayout(boolean changed, int l, int t, int r, int b)
執行layout操作時調用onLayout方法。View要給它的每個Child設定size和position。擁有Children的子類需要重寫onLayout方法並且調用每個Child的layout方法。
參數changed表示view的size或position發生變化。參數l, t, r, b分別表示相對於parent的left, top, right, bottom position。
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
測量View及其Content,確定measuredWidth和measuredHeight。在方法measure(int, int)中調用。重寫onMeasure方法時,需要調用方法setMeasuredDimension(int, int),存儲View的measuredWidth和measuredHeight。若存儲失敗,方法measure(int, int)會拋出異常IllegalStateException。可以調用super.onMeasure(int, int)方法。
除非MeasureSpec准許更大的size,否則measure的默認實現是background size。子類重寫onMeasure(int, int)提供Content的更佳測量。如果onMeasure被重寫,子類必須保證measuredWidth和measuredHeight至少是view的minHeight和minWidth。minHeight/Width通過getSuggestedMinimumHight/Width()獲取。
參數width/heightMeasureSpec表示parent強加的horizontal/vertical space要求。
void android.view.ViewGroup.layout(int l, int t, int r, int b)
給view及其descendants設定size和position。它正是layout機制的第2個步,每個parent調用它的chlidren的layout操作。使用在measure階段測量得到的size和position數據完成layout操作。擁有child的子類必須重寫onLayout方法,調用每個child的layout操作。
void android.view.ViewGroup.measureChildren(int widthMeasureSpec, int heightMeasureSpec)
請View的所有children測量themseles, 測量依據是View的MeasureSpec和padding。忽略處於GONE狀態的children,是否GONE狀態由getChildMeasureSpec來確定。
參數width/heightMeasureSpec表示view的width/height要求。