Instantiates a layout XML file into itscorresponding View objects.

LayoutInflater作用是将layout的xml布局文件实例化为View类对象。

inflate 是 LayoutInflater 的方法 作用是将指定xml中的布局找出来

我把inflate翻译为填充

LayoutInflater:

作用: 
1、对于一个没有被载入或者想要动态载入的界面, 都需要使用inflate来载入. 
2、对于一个已经载入的Activity, 就可以使用实现了这个Activiyt的的findViewById方法来获得其中的界面元素.

Inflater:

通俗的说,inflate就相当于将一个xml中定义的布局找出来.

 三种方式可以生成LayoutInflater:

  LayoutInflaterinflater=LayoutInflater.from(this);
  LayoutInflaterinflater=getLayoutInflater();
  LayoutInflaterinflater=(LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE);

ex:

LayoutInflater inflater = (LayoutInflater) context

.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

inflater.inflate(R.layout.title_view,
this, true);//找出xml 到view容器

ex2:

LayoutInflatermLi = LayoutInflater .from(this);

View view1 = mLi.inflate(R.layout.view1,
null);

View view2 = mLi.inflate(R.layout.view2,
null);

View view3 = mLi.inflate(R.layout.view3,
null);

ex3:

mViewGroup = (ViewGroup) mInflater.inflate(mresource,null);

note:第一个参数是布局,第二个参数是ViewGroup 是可以为空的

View convertView

convertView = mInflater.inflate(mresource, null);

LayoutInflater 与 inflate的更多相关文章

  1. 转载《 LayoutInflater 的inflate函数用法详解》

    很多人在网上问LayoutInflater类的用法,以及inflate()方法参数的含义,现解释如下: inflate()的作用就是将一个用xml定义的布局文件查找出来,注意与findViewById ...

  2. View.inflate和LayoutInflater的inflate方法区别

    平时ListView加载item中,adapter的getView方法中,我们经常用到: LayoutInflater.from(mContext).inflate(R.layout.it ,pare ...

  3. 三个案例带你看懂LayoutInflater中inflate方法两个参数和三个参数的区别

    关于inflate参数问题,我想很多人多多少少都了解一点,网上也有很多关于这方面介绍的文章,但是枯燥的理论或者翻译让很多小伙伴看完之后还是一脸懵逼,so,我今天想通过三个案例来让小伙伴彻底的搞清楚这个 ...

  4. Android编程之LayoutInflater的inflate方法具体解释

    LayoutInflater的inflate方法,在fragment的onCreateView方法中经经常使用到: public View onCreateView(LayoutInflater in ...

  5. 转载 LayoutInflater的inflate函数用法详解

    http://www.open-open.com/lib/view/open1328837587484.html LayoutInflater的inflate函数用法详解 LayoutInflater ...

  6. Android编程之LayoutInflater的inflate方法实例

    假设你不关心其内部实现,仅仅看怎样使用的话,直接看这篇就可以. 接上篇,接下来,就用最最简单的样例来说明一下: 用两个布局文件main 和 test: 当中,main.xml文件为: <?xml ...

  7. LayoutInflater和inflate的用法,有图有真相

    1.概述 有时候在我们的Activity中用到别的layout,并且要对其组件进行操作,比如: A.acyivity是获取网络数据的,对应布局文件为A.xml,然后需要把这个数据设置到B.xml的组件 ...

  8. Android编程之LayoutInflater的inflate方法详解

    LayoutInflater的inflate方法,在fragment的onCreateView方法中经常用到: public View onCreateView(LayoutInflater infl ...

  9. 带你看懂LayoutInflater中inflate方法

    关于inflate问题,我想很多人多多少少都了解一点,网上也有很多关于这方面介绍的文章,但是枯燥的理论或者翻译让很多小伙伴看完之后还是一脸懵逼,so,我今天想通过三个案例来让小伙伴彻底的搞清楚这个东东 ...

  10. LayoutInflater的inflate函数用法详解

    LayoutInflater作用是将layout的xml布局文件实例化为View类对象. 获取LayoutInflater的方法有如下三种: LayoutInflater inflater=(Layo ...

随机推荐

  1. Python Tkinter canvas oval原理

    Ovals, mathematically, are ellipses, including circles as a special case. The ellipse is fit into a ...

  2. JS三元运算符

    语法是 条件 ? 结果1 : 结果2; 问号(?)的前面是条件:后面跟着用冒号(:)分隔的结果1和结果2;满足条件时结果1否则结果2. 例子: var a=1; a>2?a:a=3; alert ...

  3. RemoteViews的理解和使用

    一.RemoteViews简介 作用:跨进程更新界面                         使用场景:通知栏.桌面小部件 二.在通知栏上的应用 原理:通过RemoteViews加载布局,通过 ...

  4. 使用ThinkPHP开发中MySQL性能优化的最佳21条经验

    使用ThinkPHP开发中MySQL性能优化的最佳21条经验讲解,目前,数据库的操作越来越成为整个应用的性能瓶颈了,这点对于Web应用尤其明显.关于数据库的性能,这并不只是DBA才需要担心的事,而这更 ...

  5. The package does not support the device architecture (x86). You can change the supported architectures in the Android Build section of the Project Opt

    The package does not support the device architecture (x86). You can change the supported architectur ...

  6. MSBI常见问题总结

    SSIS 1.对连接管理器“DC”的AcquireConnection方法调用失败,错误代码0xC0209303.可能在此之前已经发出错误消息,提供了有关AcquireConnection方法调用失败 ...

  7. 关于KeyEvent.Callback

    keycode------------>KEYCODE_BACK,KEYCODE_MENU event.getAction------->ACTION_DOWN,ACTION_UP,ACT ...

  8. SQL别名解析(转载)

    通过使用 SQL,可以为列名称和表名称指定别名(Alias). 其实,select列的时候取别名有三种方法,这三种方法并不是所有数据库都适用. 方法一.直接在字段名称后面加上别名,中间以空格隔开. 方 ...

  9. 什麼是 N-key 與按鍵衝突?原理說明、改善技術、選購注意完全解析

    不管是文書處理或遊戲中,我們都經常會使用到組合鍵,也就是多顆按鍵一起按下,執行某些特定的功能.有時候你可能會發現,明明只按下2顆鍵,再按下第3顆鍵時訊號卻沒有輸出.要是打報告到一半遇到這種狀況還好,如 ...

  10. 在android画面切换时设置跟随变动的小圆圈

    首先还是老规律,上传两张效果图: 第一张图:     第二张图:    前言:我们经常在使用各类安卓APP的时候发现会有如图所示的小圆圈显示当前页所在的,甚至一般来说我们的android桌面上也应该有 ...