日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁 > 芯聞號(hào) > 充電吧
[導(dǎo)讀]1、ViewGroup的測(cè)量 ? public abstract class ViewGroup extends Viewimplements ViewManager ViewParent j

1、ViewGroup的測(cè)量 ? public abstract class ViewGroup extends View
implements ViewManager ViewParent java.lang.Object ???? android.view.View ? ???? android.view.ViewGroup Class Overview

A ViewGroup is a special view that can contain other views (called children.) The view group is the base class for layouts and views containers.

對(duì)于ViewGroup來說除了完成自身的measure過程外,還要遍歷去調(diào)用所有子元素的measure方法,各子元素再遞歸去執(zhí)行這個(gè)過程。ViewGroup提供了一個(gè)measureChildren方法:

protected voidmeasureChildren (int widthMeasureSpec, int heightMeasureSpec) ?

Ask all of the children of this view to measure themselves, taking into account both the MeasureSpec requirements for this view and its padding. We skip children that are in the GONE state The heavy lifting is done in getChildMeasureSpec.

ParametersThe width requirements for this viewThe height requirements for this view

protected?void?measureChildren(int?widthMeasureSpec,int?heightMeasureSpec){
	final?int?size?=?mChildrenCount;
	final?View[]?children?=?mChildren;
	for(int?i?=?0;i?<?size;?++i){
		final?View?child?=?children[i];
		if((child.mViewFlags?&?VISIBILITY_MASK)?!=?GONE){
			measureChild(child,widthMeasureSpec,heightMeasureSpec);
		}
	}
}

?

從上面的源碼看,ViewGroup在measure時(shí),會(huì)對(duì)每一個(gè)元素進(jìn)行measure。

measureChild方法:

protected?void?measureChild(View?child,int?parentWidthMeasureSpec,int?parentHeightMeasureSpec){
	final?LayoutParams?lp?=?child.getLayoutParams();
	final?int?childWidthMeasureSpec?=?getChildMeasureSpec(parentWidth?-?MeasureSpec,mPaddingLeft?+?mPaddingRight,lp.width);
	final?int?childHeightMeasureSpec?=?getChildMeasureSpec(parentHeight?-?MeasureSpec,mPaddingTop?+?mPaddingBottom,lp.height);
	child.measure(childWidthMeasureSpec,?childHeightMeasureSpec);
}


measureChild的思想就是取出子元素的LayoutParams,再通過getChildMeasureSpec來獲取子元素的MeasureSpec,接著直接將MeasureSpec傳遞給View的measure方法進(jìn)行測(cè)量。

?

2、ViewGroup的繪制

?

ViewGroup通常情況下不需要繪制,如果不用指定ViewGroup的背景顏色,其onDraw()方法都不會(huì)被調(diào)用。ViewGroup會(huì)使用dispatchDraw()方法繪制其子View,過程同樣是遍歷所有子View,并調(diào)用子View的繪制方法來完成繪制。

widthMeasureSpecheightMeasureSpec
本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關(guān)閉