java.lang.Object

    android.view.LayoutInflater

This class is used to instantiate layout XML file into its corresponding View objects.

 It is never be used directly -- 

 use getLayoutInflater()  or getSystemService(String)  to retrieve a standard LayoutInflater instance 

 that is already hooked up to the current context and correctly configured for the device you are running on. 

 For example:



LayoutInflater inflater = (LayoutInflater)context.getSystemService

      Context.LAYOUT_INFLATER_SERVICE);

常用方法有:

public View inflate (int resource, ViewGroup root)

Since: API Level 1



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.

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. 

注意:如果root被提供的话,在把新生成的View连接到root后,返回root.否者返回的是新生成的View

public View inflate (int resource, ViewGroup root, boolean attachToRoot)

Since: API Level 1



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的话,在把新生成的View连接到root,返回root.否者返回的是新生成的View。

如果root被提供但attachToRoot为FALSE的话,root只是把它的LayoutParams参数给新生成的View用,

不会把新生成的View连接到root。当然返回的是新生成的View。

版权声明:本文为博主原创文章,未经博主允许不得转载。

inflate用一个XML源填充view. LayoutInflater的更多相关文章

  1. [Android FrameWork 6.0源码学习] LayoutInflater 类分析

    LayoutInflater是用来解析XML布局文件,然后生成对象的ViewTree的工具类.是这个工具类的存在,才能让我们写起Layout来那么省劲. 我们接下来进去刨析,看看里边的奥秘 //调用i ...

  2. Android数据填充器LayoutInflater

    LayoutInflater类在应用程序中比较实用,可以叫布局填充器,也可以成为打气筒,意思就是将布局文件填充到自己想要的位置,LayoutInflater是用来找res/layout/下的xml布局 ...

  3. Android通过xml生成创建View的过程解析

    Android的布局方式有两种,一种是通过xml布局,一种是通过java代码布局,两种布局方式各有各的好处,当然也可以相互混合使用.很多人都习惯用xml布局,那xml布局是如何转换成view的呢?本文 ...

  4. android开发中一个activity如何调用另一个xml中的控件

    有时候,我们需要在一个activity中使用另一个activity中的控件,这时候就不能直接findViewById,不然会报错指向空对象,这时就需要像下面这样做. LayoutInflater fa ...

  5. at android.view.LayoutInflater.createViewFromTag的错误原因

    创建对话框时出现下面的错误: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean ...

  6. php动态生成一个xml文件供swf调用

    <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdo ...

  7. 写一个xml文件到磁盘的方法

    /** * 往磁盘上写一个xml文件 * * <?xml version="1.0" encoding="UTF-8" standalone=" ...

  8. 一个lucene源码分析的博客

    ITpub上的一个lucene源码分析的博客,写的比较全面:http://blog.itpub.net/28624388/cid-93356-list-1/

  9. 判断本地系统目录下是否存在XML文件,如果不存在就创建一个XMl文件,若存在就在里面执行添加数据

    这是我为项目中写的一个测试的例子, 假如,您需要这样一个xml文件, <?xml version="1.0" encoding="utf-8"?> ...

随机推荐

  1. servlet接收request请求的json数据

    此次使用的是alibaba的fastjson:jar包为fastjson-1.2.7.jar 参考:https://www.qingtingip.com/h_229797.html 思路:由于此次接收 ...

  2. lc287 Game of Live

    lc287 Game of Live 难点在于不能使用额外的空间. 观察到数组中每一个元素要么为1要么为0,32位int只用了一位,可以利用bit操作,将第二次state存储到int变量的倒数第二位中 ...

  3. PHP实现微信小程序支付完整版,可以借鉴!

    本文实例为大家分享了php实现小程序支付的具体代码,供大家参考,具体内容如下 环境: tp3.2.3  + 小程序 微信支付功能开通 Step1:  下载PHP 支付SDK(下载地址)  放到Libr ...

  4. 项目中的那些事---Java反射的应用

    最近工作中遇到一个这样的问题: 为某个项目中的所有接口做一个测试工具,使用java Swing技术,该项目有不同的版本,不是所有版本中的接口都是相同的,而我做的工具需要兼容所有版本. 于是就引入了这样 ...

  5. 常用命令6--文件搜索命令4-grep

    查找不包含size字符串的文件.

  6. neo4j中对节点关系和聚类的思考

    由于neo4j在查找过程中具有事务,所以查询的速度非常慢!给出的建议如下: 一,将所有查询放在一个Session中,当所有查询完毕以后在关闭Driver和Session: 二,使用neo4j连接池,使 ...

  7. Mac下升级node到最新版本

    建议先装n,再用n把node升级到最新稳定版: $ npm install -g n $ n stable

  8. Springboot 创建的maven获取resource资源下的文件的两种方式

    Springboot 创建的maven项目 打包后获取resource下的资源文件的两种方式: 资源目录: resources/config/wordFileXml/wordFileRecord.xm ...

  9. vue2.0 兼容ie9及其以上

    vue官方的意思是vue项目可以在ie8以上的ie版本中运行 但其实使用vue-cli构建的项目也还是不能在ie8[ie9,ie10,ie11]以上的版本中运行 下面就来讲vue如何在ie8以上ie版 ...

  10. 2018-8-10-C#-不能用于文件名的字符

    title author date CreateTime categories C# 不能用于文件名的字符 lindexi 2018-08-10 19:16:52 +0800 2018-02-22 1 ...