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)
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
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.
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.

  意思就是:root参数表示,如果attachToRoot为true的话,那么root为这个resource布局的父布局。如果attachToRoot为false,那么root仅仅为打气的这个布局提供了一组LayoutParams,暂时可以理解为所有的布局都需要一个LayoutParams,所以必须提供.

其原理目前我还没有完全理解,基本可以总结为,在Fragment的OnCreateView方法中,需要用这个 View view = inflater.inflate(R.layout.my_fragment_layout, container, false);,因为Fragment的布局本身就是根布局

在自定义ViewGroup中,要用这个

//把生成的布局当做子类加入到当前控件中
//this表示当前这个自定义ViewGroup
View view = LayoutInflater.from(context).inflate(R.layout.mapmodel_relat_view, this, true);

inflate的使用注意事项的更多相关文章

  1. 关于Merge的整理--Merge的使用方法和注意事项的Demo

    上一篇文章中讲到了Merge的用法和注意事项,所以本人就想,做了一个Demo进行验证下. 一.Merge的使用 (1)activity中的onCreate方法中的setContentView(R.la ...

  2. ListView嵌套GridView使用详解及注意事项

    ListView嵌套GridView即ListView的每个Item中都包含一个GridView:需要注意的是由于ListView和GridView都是可滑动的控件. 所以需要自定义GridView, ...

  3. Android学习_注意事项

    一. Fragment中加载ListView public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle ...

  4. jQuery UI resizable使用注意事项、实时等比例拉伸及你不知道的技巧

    这篇文章总结的是我在使用resizable插件的过程中,遇到的问题及变通应用的奇思妙想. 一.resizable使用注意事项 以下是我在jsfiddle上写的测试demo:http://jsfiddl ...

  5. Windows Server 2012 NIC Teaming介绍及注意事项

    Windows Server 2012 NIC Teaming介绍及注意事项 转载自:http://www.it165.net/os/html/201303/4799.html Windows Ser ...

  6. TODO:Golang指针使用注意事项

    TODO:Golang指针使用注意事项 先来看简单的例子1: 输出: 1 1 例子2: 输出: 1 3 例子1是使用值传递,Add方法不会做任何改变:例子2是使用指针传递,会改变地址,从而改变地址. ...

  7. app开发外包注意事项,2017最新资讯

    我们见过很多创业者,栽在这app外包上.很多创业者对于app外包这件事情不是特别重视,以为将事情交给app外包公司就完事了,实际上不是的.无论是从选择app外包公司还是签订合同.售后维护等各方面都有许 ...

  8. favicon.ioc使用以及注意事项

    1.效果 2.使用引入方法 2.1 注意事项:(把图标命名为favicon.ico,并且放在根目录下,同时使用Link标签,多重保险) 浏览器默认使用根目录下的favicon.ico 图标(如果你并没 ...

  9. ORACLE分区表梳理系列(二)- 分区表日常维护及注意事项(红字需要留意)

    版权声明:本文发布于http://www.cnblogs.com/yumiko/,版权由Yumiko_sunny所有,欢迎转载.转载时,请在文章明显位置注明原文链接.若在未经作者同意的情况下,将本文内 ...

随机推荐

  1. Majority Element in an Array

    Problem Statement Given a large array of non-negative integer numbers, write a function which determ ...

  2. Activiti(工作流)如何关联业务表

    注(version:5.15.1) 1.部署流程(定义流程) InputStream in = new FileInputStream(file); ZipInputStream zipInputSt ...

  3. How to use php serialize() and unserialize()

    A PHP array or object or other complex data structure cannot be transported or stored or otherwise u ...

  4. MUI——页面的创建、显示、关闭

    一.打开子页面 mui.init({ subpages:[{ url:your-subpage-url,//子页面HTML地址,支持本地地址和网络地址 id:your-subpage-id,//子页面 ...

  5. Python基础篇-day6

    本节简介: 1.模块1.1 时间模块1.2 random模块1.3 shutil模块1.4 shelve模块1.5 XML模块1.6 ConfigParser模块1.7 hashlib模块1.8 lo ...

  6. ExceptionDemo

    功能: 利用struts.xml 捕获异常  不满足这三个值就报异常 1.web.xml <?xml version="1.0" encoding="UTF-8&q ...

  7. Paxos算法简单介绍

    一种基于消息传递且具有高度容错特性的一致性算法.解决在存在宕机或者网络异常的集群中对某个数据的值达成一致性,并且保证无论在发生以上任何异常都不会破坏整个系统的一致性,具有容错性. Paxos算法实现的 ...

  8. java复习-多线程

    和线程之间的关系: 进程:进程是程序的一次动态执行过程,他经理了代码加载,执行到执行完毕的一个完整过程,这个过程也是进程本身从产生,发展到最终消亡的过程. 线程:线程是实现并发机制的一种有效手段,进程 ...

  9. JavaBean 反射机制实现自动配置数据

    声明:该版本是没完成的.该博文只做记录代码用 String memberType(String name) throws Exception { return getType(getClass().g ...

  10. 3-jQuery - AJAX get()

    介绍 GET 基本上用于从服务器获得(取回)数据.注释:GET 方法可能返回缓存数据. 格式 $.get(URL,callback); //必需的 URL 参数规定您希望请求的 URL. //可选的 ...