FrameWork之View的繪製過程(下)

2021-06-27 18:52:20 字數 3380 閱讀 5334

首先說viewgroup類吧,因為該類是所有容器類的父類,所謂容器類就是布局類,比如linearlayout、tablelayout等,用來容納view控制項的。

viewgroup提供了三個類似的方法用於對子檢視進行measure()操作:

①measurechildren():正如其名,children是複數啊,該方法內部使用for迴圈呼叫measurechild()方法對每乙個子檢視進行measure操作,原始碼如下:

protected void measurechildren(int widthmeasurespec, int heightmeasurespec) 

}}

② measurechild():為指定的子檢視進行measure操作,measurechildren()方法會呼叫此方法,原始碼如下:

protected void measurechild(view child, int parentwidthmeasurespec,

int parentheightmeasurespec)

我記得好像說過layoutparams類是個什麼情況 - -沒有詳細拿出來,layoutparams類相當重要啊,每乙個容器類都會有乙個layoutparams的內部類,乙個檢視會使用layoutparams類來封裝必要資訊告訴父容器怎麼去為自己布局,viewgroup的layoutparams以及marginlayoutparams類如下:

public static class layoutparams .

*///這個值熟悉嗎,這是4.1.2版本了,此屬性已經不被推薦使用

public static final int fill_parent = -1;

//熟悉嗎

public static final int match_parent = -1;

public static final int wrap_content = -2;

public int width;

public int height;

public layoutanimationcontroller.animationparameters layoutanimationparameters;

public layoutparams(context c, attributeset attrs)

public layoutparams(int width, int height)

/*** @param source the layout params to copy from.

*/public layoutparams(layoutparams source)

/*** used internally by marginlayoutparams.

* @hide

*/layoutparams()

protected void setbaseattributes(typedarray a, int widthattr, int heightattr)

/*** @hide

*/public void onresolvelayoutdirection(int layoutdirection)

/*** @hide

*/public string debug(string output) ";

}public void ondebugdraw(view view, canvas canvas)

protected static string sizetostring(int size)

if (size == match_parent)

return string.valueof(size);}}

/*** per-child layout information for layouts that support margins.

* see

*繼承了本類的layoutparams

*/public static class marginlayoutparams extends viewgroup.layoutparams else

a.recycle();

}public marginlayoutparams(int width, int height)

/*** copy constructor. clones the width, height and margin values of the source.

* @param source the layout params to copy from.

*/public marginlayoutparams(marginlayoutparams source)

/***

*/public marginlayoutparams(layoutparams source)

public void setmargins(int left, int top, int right, int bottom)

/*** sets the relative margins, in pixels. a call to

* @hide

*/public void setmarginsrelative(int start, int top, int end, int bottom)

/*** returns the start margin in pixels

* @hide

*/public int getmarginstart()

/*** @hide

*/public int getmarginend()

/*** @hide

*/public boolean ismarginrelative()

/*** @hide

*/@override

public void onresolvelayoutdirection(int layoutdirection)

}/**

* @hide

*/@override

public void ondebugdraw(view view, canvas canvas)

}

③measurechildwithmargins():該函式與measurechild的唯一區別就是measure的時候會考慮把margin 以及padding作為子檢視的一部分。原始碼如下!:

protected void measurechildwithmargins(view child,

int parentwidthmeasurespec, int widthused,

int parentheightmeasurespec, int heightused)

View的事件體系之View的位置引數

如圖所示,為view的位置座標與父容器的關係圖,此圖 於老任的 android開發藝術探索 這本書,感興趣的同學可以去看下,以此我們來簡單介紹下view的位置引數的相關知識。首先是4個基本屬性top left right bottom 如圖,這幾個屬性,都是view相對于父容器的資訊 top 左上角...

Cocoapods與Framework的使用

cocoapods的安裝使用請參照 安裝cocoapods 開啟終端,輸入命令 sudo gem install cocoapods 等待幾秒後即可安裝成功。使用cocoapods,以alamofire為例 分三個步驟 1 在專案檔案關中建立podfile 檔案,podfiel檔案是 cocoapo...

a與framework的不同

ios中靜態庫與動態庫的區別 1.存在形式 靜態庫 a 和.framework 動態庫 dylib和.framework 2.使用上的不同 靜態庫 鏈結時,會完整的複製到可執行檔案中,被多次使用就會產生多分冗餘的拷貝。動態庫 鏈結時不複製,只在程式執行時由系統動態載入到記憶體中供程式呼叫,系統僅載入...