private void measureView(View child) {
ViewGroup.LayoutParams params = child.getLayoutParams();
if (params == null) {
params = new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
}
int childWidthSpec = ViewGroup.getChildMeasureSpec(0, 0,
params.width);
/*getChildMeasureSpec
在加入API級別1
INT getChildMeasureSpec(INT規(guī)范,
INT填充炸卑,
INT childDimension)
是否measureChildren困難的部分:搞清楚MeasureSpec
傳遞給特定的孩子既鞠。此方法計算出正確的MeasureSpec用于一
個子視圖的一個維度(高度或?qū)挾龋N覀兊哪繕?biāo)是資訊從Meas
ureSpec與孩子的LayoutParams結(jié)合起來盖文,以獲得最好的結(jié)果嘱蛋。
例如,如果這個觀點知道它的大小(因為它MeasureSpec有整整模式)
浑槽,并且孩子在的LayoutParams已經(jīng)表示蒋失,它希望成為的尺寸與父母一樣,
家長應(yīng)讓孩子布局給出精確的尺寸桐玻。/
int lpHeight = params.height;
int childHeightSpec;
if (lpHeight > 0) {
childHeightSpec = View.MeasureSpec.makeMeasureSpec(lpHeight,
View.MeasureSpec.EXACTLY);
//makeMeasureSpec創(chuàng)建基于所提供的大小和模式度量規(guī)范篙挽。
} else {
childHeightSpec = View.MeasureSpec.makeMeasureSpec(0,
View.MeasureSpec.UNSPECIFIED);//
/ int AT_MOST
測量規(guī)范方式:因為它要到指定大小的孩子可大。
int EXACTLY
測量規(guī)范模式:父母已決定為孩子的確切大小镊靴。
int UNSPECIFIED
測量規(guī)范模式:父母沒有強加給孩子任何約束铣卡。/
}
child.measure(childWidthSpec, childHeightSpec);
/空隙的措施(INT widthMeasureSpec,
INT heightMeasureSpec)
這就是所謂的找出一個觀點應(yīng)該多大偏竟。父供給在寬度和高度參數(shù)約束信息煮落。
一針對實際計測操作被執(zhí)行。在 onMeasure(int, int)通過此方法調(diào)用的踊谋。因此蝉仇,只有 onMeasure(int, int)能夠而且必須由子類覆蓋。
參數(shù)
widthMeasureSpec int:所施加由母公司水平空間要求
heightMeasureSpec int:垂直空間的要求強加父
*/
}