編輯:高級開發
Java代碼
childWidthMeasureSpec = getRootMeasureSpec(desiredWindowWidth, lp.width);
childHeightMeasureSpec = getRootMeasureSpec(desiredWindowHeight, lp.height);
desiredWindowWidth 根據代碼可知,一般情況就是屏幕的寬度;desiredWindowHeight 根據代碼可知,一般情況就是屏幕的寬度-狀態欄高度;
/**
* Figures out the measure spec for the root vIEw in a window based on it's
* layout params.
*
* @param Windowsize
* The available width or height of the window
*
* @param rootDimension
* The layout params for one dimension (width or height) of the
* window.
*
* @return The measure spec to use to measure the root vIEw.
*/
private int getRootMeasureSpec(int Windowsize, int rootDimension) {
int measureSpec;
switch (rootDimension) {
case VIEwGroup.LayoutParams.MATCH_PARENT:
// Window can't resize. Force root vIEw to be Windowsize.
measureSpec = MeasureSpec.makeMeasureSpec(Windowsize, MeasureSpec.EXACTLY);
break;
case VIEwGroup.LayoutParams.WRAP_CONTENT:
// Window can resize. Set max size for root vIEw.
measureSpec = MeasureSpec.makeMeasureSpec(Windowsize, MeasureSpec.AT_MOST);
break;
default:
// Window wants to be an exact size. Force root vIEw to be that size.
measureSpec = MeasureSpec.makeMeasureSpec(rootDimension, MeasureSpec.EXACTLY);
break;
}
return measureSpec;
}
host.measure(childWidthMeasureSpec, childHeightMeasureSpec);
childWidthMeasureSpec = getRootMeasureSpec(desiredWindowWidth, lp.width);
childHeightMeasureSpec = getRootMeasureSpec(desiredWindowHeight,
接上頁
lp.height);desiredWindowWidth 根據代碼可知,一般情況就是屏幕的寬度;desiredWindowHeight 根據代碼可知,一般情況就是屏幕的寬度-狀態欄高度;
/**
* Figures out the measure spec for the root vIEw in a window based on it's
* layout params.
*
* @param Windowsize
* The available width or height of the window
*
* @param rootDimension
* The layout params for one dimension (width or height) of the
* window.
*
* @return The measure spec to use to measure the root vIEw.
*/
private int getRootMeasureSpec(int Windowsize, int rootDimension) {
int measureSpec;
switch (rootDimension) {
case VIEwGroup.LayoutParams.MATCH_PARENT:
// Window can't resize. Force root vIEw to be Windowsize.
measureSpec = MeasureSpec.makeMeasureSpec(Windowsize, MeasureSpec.EXACTLY);
break;
case VIEwGroup.LayoutParams.WRAP_CONTENT:
// Window can resize. Set max size for root vIEw.
measureSpec = MeasureSpec.makeMeasureSpec(Windowsize, MeasureSpec.AT_MOST);
break;
default:
// Window wants to be an exact size. Force root vIEw to be that size.
measureSpec = MeasureSpec.makeMeasureSpec(rootDimension, MeasureSpec.EXACTLY);
break;
}
return measureSpec;
}
host.measure(childWidthMeasureSpec, childHeightMeasureSpec);
注意ViewRoot並不是View,不過是ViewParent。刷新屏幕都是在這個類中,host就是PhoneWindow的DecorVIEw。
Java代碼
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec),
getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec));
}
/**
接上頁
* Utility to return a default size. Uses the supplIEd size if the
* MeasureSpec imposed no contraints. Will get larger if allowed
* by the MeasureSpec.
*
* @param size Default size for this vIEw
* @param measureSpec Constraints imposed by the parent
* @return The size this vIEw should be.
*/
public static int getDefaultSize(int size, int measureSpec) {
int result = size;
int specMode = MeasureSpec.getMode(measureSpec);
int specSize = MeasureSpec.getSize(measureSpec);
switch (specMode) {
case MeasureSpec.UNSPECIFIED:
result = size;
break;
case MeasureSpec.AT_MOST:
case MeasureSpec.EXACTLY:
result = specSize;
break;
}
return result;
}
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec),
getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec));
}
/**
* Utility to return a default size. Uses the supplIEd size if the
* MeasureSpec imposed no contraints. Will get larger if allowed
* by the MeasureSpec.
*
* @param size Default size for this vIEw
* @param measureSpec Constraints imposed by the parent
* @return The size this vIEw should be.
*/
public static int getDefaultSize(int size, int measureSpec) {
int result = size;
int specMode = MeasureSpec.getMode(measureSpec);
int specSize = MeasureSpec.getSize(measureSpec);
switch (specMode) {
case MeasureSpec.UNSPECIFIED:
result = size;
break;
case MeasureSpec.AT_MOST:
case MeasureSpec.EXACTLY:
result = specSize;
break;
}
return result;
}
Android 是近年來在移動設備行業相當火熱的詞匯,在此我從交互設計的角度整理了此文章,文章分為三個部分,跟大家討論android的那些事兒。第一部分:成長中的and
此變量)PATHPath使得系統可以在任何路徑下識別Java命令,設為: %JAVA_HOME%\bin;%Java_HOME%\jre\binCLASSPATHCLA
android Devices是一個Android的插件自動生成的,他就是繼承了Activity 類,這個類是android運行的一個類,簡單的說就是一個界面。 gen
51CTO曾對android的系統架構做過詳細的解析。近日,Google的一位工程師Sans Serif發布了一篇博文非常清楚的描述了android系統架構,中國移動通