1. LayoutInflater. from (RecylerActivity. this ) .inflate(R.layout. my_text_view , viewGroup ,false ) ;

2. View. inflate (RecylerActivity. this,  R.layout. my_text_view , null );
这两种 inflate 的方法有什么区别呢;
首先我们通过看源码得知View。inflate()方法实际上调用的也是LayoutInflater.from(int resource, ViewGroup root, boolean attachToRoo);
其中最主要的二者区别就在于 ViewGroup  root 这个参数没有传;
下面我们来看看inflate  方法的介绍
public View inflate (int resource, ViewGroup root, boolean attachToRoot)
Added in 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.

作用:填充一个新的视图层次结构从指定的XML资源文件中
reSource:View的layout的ID
root: 生成的层次结构的根视图
return 填充的层次结构的根视图。如果参数root提供了,那么root就是根视图;否则填充的XML文件的根就是根视图。

其余几个重载的inflate函数类似。

那么root因为第二传的是null所以他的parent 就是传进去的 xml resource;第一个传了root 所以他的parent就是ViewGroup;
所以就会导致启动的应用
1. 
2.

View.inflate 和 inflater.inflate 区别相关推荐

  1. inflater.inflate 三个方法区别

    对于方法 public View inflate(@LayoutRes int resource, @Nullable ViewGroup root, boolean attachToRoot) 1. ...

  2. inflater.inflate()参数详解

    前言 今天在lint项目的代码时,又遇到了inflate方法的参数问题,之前看过相关的文章,又没有记录下来,导致时间长了就忘记了.今天再次遇到这个问题,便老老实实记录一下LayouInflater中i ...

  3. inflater.inflate使用详解

    原文地址:https://possiblemobile.com/2013/05/layout-inflation-as-intended/ Layout inflation is the term u ...

  4. inflater.inflate的理解

    View rl = inflater.inflate(R.layout.mytest, mListCon,true); 如果是第三个参数是false,就是不要将布局文件加载到root中,返回值是布局文 ...

  5. android inflater,探索 Android Inflater.inflate()

    android-knowledge.jpg 在 Android 开发中,有很多看起来 "约定俗成" 的代码,有时候不妨停下来想一想深层次的含义.最近我在给 Fragment 填充布 ...

  6. Inflate()---Android之Inflate()方法用途

    Inflate()作用就是将xml定义的一个布局找出来,但仅仅是找出来而且隐藏的,没有找到的同时并显示功能.最近做的一个项目就是这一点让我迷茫了好几天. android上还有一个与Inflate()类 ...

  7. android inflate,Android 关于inflate

    通俗的说,inflate就相当于将一个xml中定义的布局找出来. 因为在一个Activity里如果直接用findViewById()的话,对应的是setConentView()的那个layout里的组 ...

  8. android View.isShown() 和 getVisibility() 的区别

    有时候,我们会判断当前我们的View 是否可见. 常见的判断如: View.getVisibility() == View.VISIBLE 还有一种是 View.isShown(). 这两种有什么区别 ...

  9. Android: Custom View和include标签的区别

    Custom View, 使用的时候是这样的: <com.example.home.alltest.view.MyCustomViewandroid:id="@+id/customVi ...

最新文章

  1. MyBatis千万级数据查询解决方案,避免OOM
  2. layui导入 加载动画_厉害了!这个免费神器帮你无脑做施工动画
  3. OpenCV各个模块/各个文件夹的含义
  4. VTK计算网格模型上的最短路径
  5. zoj 3761 Easy billiards 并查集+dfs
  6. composer 完整路径才能访问_Win7系统IIS,无法访问ASP,提示错误 '80004005'
  7. luci L大_油耗最低1.4L!开这四款车一个月都不用进加油站
  8. 在Windows Media Center中收听超过100,000个广播电台
  9. 作为一个甘肃天水人,我对罐罐茶有一种特殊的情怀
  10. # 20155337 2017-2018-1 《信息安全系统设计基础》第二周课堂实践+myod
  11. html计算一个数组所有元素的和,函数bsxfun,两个数组间元素逐个计算的二值操作...
  12. linux下运行python unitest_Python单元测试unittest代码详解
  13. [转载]HTML5 Audio/Video 标签,属性,方法,事件汇总
  14. 黑马程序员 re模块的高级用法 学习笔记
  15. LCD1602字符串显示(STM32F103)
  16. 23_ZYNQ7020开发板_USB驱动
  17. linux安装globalsign证书,免费安装 GlobalSign 安全签章 GlobalSign Secured Seal
  18. android wifi 无法连接电脑连接,没有数据线,Wifi也能连接Android真机开发调试!彻底解决“无法识别的USB设备”等数据线连接问题!...
  19. 读取excel中的表格数据到字典dict中--python
  20. dpi和ppi换算_八一八那些px、pt、ppi、dpi、dp、sp之间的关系

热门文章

  1. QSqlDatabase::addDatabase奔溃及连接失败解决
  2. Ubuntu18.04图片信息查看器(四十九)
  3. 华为设备配置VRRP与路由联动监视上行链路
  4. 小米手机查找位置定位服务器,如何定位查找自己的小米手机?
  5. orm和mysql_ORM框架与mysql数据库的无缝对接
  6. 让人流泪的手机号码(转)
  7. 基于VBA的Excel抽奖软件
  8. python第一天作业
  9. iOS - 抖音效果
  10. 艾司博讯:拼多多修改价格对权重的影响