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. Javascript-循环输出菱形,并可菱形自定义大小

    var Cen = 6;//定义菱形中部为第几行(起始值为0) //for循环输出菱形 document.write("<button onclick='xh()'>点我for循 ...

  2. c++设计模式:访问者模式(visitor模式)

    1.c语言中回调基本都过函数指针来完成.c++中主要通过接口的方式完成回调.而visitor就是实现接口回调的一种方式. 1.首先定义个一个接口visitor类, class classVisitor ...

  3. 手机前端开发调试利器-vConsole

    最近因为做抽奖页面,在android上可以使用手机连上电脑后用chrome浏览器chrome://inspect进行页面探测,但是ios中的页面就不能这样探测 在网上搜索后发现此插件,大大解决了问题 ...

  4. Windows Sublime text3 搭建Go语言环境

    第一步:Go环境和配置 1.安装 Go 开发环境(省略),假设Go安装目录为 C:\Go 2.配置环境变量,下面两个环境变脸没有就加上. 资料参考:http://studygolang.com/art ...

  5. PHP--时间格式处理

    Ymd格式转Y-m-d或转成时间戳将Ymd格式如19930811转成1993-08-11格式 date('Y-m-d',strtotime('19930811') 将Ymd格式如19930811转成时 ...

  6. 在多版本python的pip的安装与对应包的安装

    最近花了好长时间在搞这个,由于Deepin下python有两个版本,并且都没有安装pip,之前的博文默认安装pip给python2.7,结果各种问题,在此将之前走过的弯路整合起来: 首先,安装pip ...

  7. 关于neo4j的嵌入式和驱动包模式该如何选择,还请解惑

    看了网上的一些资料和Neo4j权威指南这本书.与图遍历相关的介绍都是基于嵌入式模式下的java Api.但是个人觉得在实际的项目中,嵌入式的模式,代码必须放在数据库所在服务器上,且服务器的启停操作都在 ...

  8. web前端学习(二)html学习笔记部分(3)--range对象

    1.2.8  html5编辑api之range对象(一) 1.2.8.1  Range 对象基本概念 Range 对象的基本概念,通过使用 Range 对象所提供的方法实现一个鼠标选取内容,通过点击按 ...

  9. selenium 常见问题之 nknown error: call function result missing ‘value’

    运行时候出现错误提示如下: 出现该问题原因:chrome浏览器自动升级.导致和chromedriver支持的版本不匹配. 解决方案有两种(本人采用的是第一种方式解决办法.): 1.下载和当前使用的ch ...

  10. 从0开始学习 GitHub 系列之「05.Git 进阶」

    关于 Git 相信大家看了之前一系列的文章已经初步会使用了, 但是关于Git还有很多知识与技巧是你不知道的,今天就来给大家介绍下一些 Git 进阶的知识. 1. 用户名和邮箱 我们知道我们进行的每一次 ...