美文网首页
关于LayoutInflater.inflate()

关于LayoutInflater.inflate()

作者: pri17 | 来源:发表于2016-12-19 16:28 被阅读0次

    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
    参数介绍:
    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的话,那第一个参数的layout文件就会被填充并附加在第二个参数所指定的ViewGroup内。方法返回结合后的View,根元素是第二个参数ViewGroup。如果是false的话,第一个参数所指定的layout文件会被填充并作为View返回。这个View的根元素就是layout文件的根元素。不管是true还是false,都需要ViewGroup的LayoutParams来正确的测量与放置layout文件所产生的View对象。
    一root是this, attachToRoot是false.

    相关文章

      网友评论

          本文标题:关于LayoutInflater.inflate()

          本文链接:https://www.haomeiwen.com/subject/jsytvttx.html