LayoutInflate.inflate参数解释

加载布局

  • public View inflate (int resource, ViewGroup root)
      Inflate a new view hierarchy from the specified xml resource. Throws InflateException if there is an error.
    ** Parameters **
      resource  ID for an XML layout resource to load (e.g., R.layout.main_page)(加载的布局id)
      root  Optional view to be the parent of the generated hierarchy.(给该布局的外部再嵌套一层父布局,但不是把当前布局放入到界面已有布局中,比如xml界面,这个方法只是单纯的返回一个view对象。默认attachToRoot是true)
    ** Returns **
      The root View of the inflated hierarchy. If root was supplied, this is the root View; otherwise it is the root of the inflated XML file.

  • public View inflate (int resource, ViewGroup root, boolean attachToRoot)
      Inflate a new view hierarchy from the specified xml resource. Throws InflateException if there is an error.
    Parameters
      resource  ID for an XML layout resource to load (e.g., R.layout.main_page)(加载的布局id)
      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.)(如果第3个参数是true,这个参数的意思同上,如果第3个参数是false,这个参数仅仅是为返回的view提供LayoutParams的单纯对象)
      attachToRoot  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.(返回的view是否应用root的LayoutParams,如果是false,第2个参数仅仅用来给提供LayoutParams)
    Returns
      The root View of the inflated hierarchy. If root was supplied and attachToRoot is true, this is root; otherwise it is the root of the inflated XML file.

你可能感兴趣的:(LayoutInflate.inflate参数解释)