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. inception cenOS 安装

    inception手册http://mysql-inception.github.io/inception-document/install/ 执行命令sh inception_build.sh,ce ...

  2. mycat 概述

    从开始接触mycat,到现在为止也有三个多月的时间了,目前在测试环境中已经初步应用!大概可以总结一下了 mycat是一个数据库中间件,也可以理解为是数据库代理.在架构体系中是位于数据库和应用层之间的一 ...

  3. Spring.net 学习

    最近一段时间,在学习spring.net方面的知识,spring.net是什么,spring.net是用来干什么的,我们这里就不在介绍了,spring.net有两方面的内容---IOC(DI)与AOP ...

  4. laravel php artisan migrate 数据迁移时出现的[HY000][1045]错误

    (zz找了块一个小时才发现)主要的错误在于.env文件和database.php的配置不匹配. 1.找到.env文件 2.更改数据库表账密 3.改database.php的数据库账密 4.完成

  5. iOS 10权限崩溃问题

    手机升级到iOS10 Beta版本后,再次进行真机调试时会遇见权限崩溃问题,崩溃原因如下:This app has crashed because it attempted to access pri ...

  6. XOR and Favorite Number(莫队算法+分块)

    E. XOR and Favorite Number time limit per test 4 seconds memory limit per test 256 megabytes input s ...

  7. JavaScript中prompt()函数的用法。

    定义和用法 prompt()方法用于显示一个带有提示信息,并且用户可以输入的对话框. 语法 prompt(text,defaultText); 参数 描述 text 可选.要在对话框中显示的提示信息( ...

  8. 运用bootstrap框架的时候 引入文件的问题

    还要下个jquery,因为bootstrap的js是用jquery写的如果在同一个目录下<html><head><link href="css/bootstra ...

  9. push类型消息中间件-消息订阅者(一)

    1.订阅者的声明方式 我们以spring组件化的方式,声明一个消息订阅者,对于消息订阅者关心的主要有: topic: 一级消息类型(又名消息主题).如TRADE 消息类型:二级消息类型,区别同一Top ...

  10. Okhttp设置http缓存,在没有网络的情况下加载http缓存里面的内容

    HTTP_CACHE_FILENAME为缓存地址根路径: private final String HTTP_CACHE_FILENAME = "HttpCache"; priva ...