LayoutInflater. from(Context context): Obtains the LayoutInflater from the given context.
inflate(int resource,ViewGroup root, boolean attachToRoot): Inflate a new view hierarchy from the specified XML node. Throws InflateException if there is an error.
Important For performance reasons, view inflation relies heavily on pre-processing of XML files that is done at build time. Therefore, it is not currently possible to use LayoutInflater with an XmlPullParser over a plain XML file at runtime.
返回值是View
參數(shù)介紹:
resource: layout資源,XML dom node containing the description of the view hierarchy.
root: Optional view to be the parent of the generated hierarchy (if attachToRoot is true), or else simply an object that provides a set of LayoutParams values for root of the returned hierarchy (if attachToRoot is false.)
attachToRoot: boolean, Whether the inflated hierarchy should be attached to the root parameter? If false, root is only used to create the correct subclass of LayoutParams for the root view in the XML.
如果attachToRoot是true的話,那第一個參數(shù)的layout文件就會被填充并附加在第二個參數(shù)所指定的ViewGroup內(nèi)。方法返回結(jié)合后的View,根元素是第二個參數(shù)ViewGroup。如果是false的話,第一個參數(shù)所指定的layout文件會被填充并作為View返回。這個View的根元素就是layout文件的根元素。不管是true還是false,都需要ViewGroup的LayoutParams來正確的測量與放置layout文件所產(chǎn)生的View對象。
一root是this, attachToRoot是false.
關(guān)于LayoutInflater.inflate()
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。
相關(guān)閱讀更多精彩內(nèi)容
- 一、適用場景 ListViewListview是一個很重要的組件,它以列表的形式根據(jù)數(shù)據(jù)的長自適應展示具體內(nèi)容,用...
- 由LayoutInflater談起 layoutInflater.inflate(int resource, Vi...