原文出自:网络
第一种:
public View inflate (int resource, ViewGroup root)
reSource:View的layout的ID
root:如果返回null,则将此View作为根,此时既可以应用此View中的其他控件了。
如果返回!null, 则将默认的layout作为View的根。
第二种:
public View inflate (XmlPullParser parser, ViewGroup root)
parser:你需要解析xml的解析接口
root:如果返回null,则将此View作为根,此时既可以应用此View中的其他控件了。
如果返回!null, 则将默认的layout作为View的根。
第三种:
public View inflate (XmlPullParser parser, ViewGroup root, boolean attachToRoot)
parser:你需要解析View的xml的解析接口
root:如果返回null,则将此View作为根,此时既可以应用此View中的其他控件了。
如果返回!null, 则将默认的layout作为View的根。
attachToRoot:
ture:也就将此解析的xml作为View根
fase:则为默认的xml,做为根视图View
第四种:
public View inflate (int resource, ViewGroup root, boolean attachToRoot)
resource:View的layout的ID
root:如果返回null,则将此View作为根,此时既可以应用此View中的其他控件了。
如果返回!null, 则将默认的layout作为View的根。
attachToRoot:
ture:也就将此解析的xml作为View根
fase:则为默认的xml,做为根视图View
同时在此讲讲让我去API中去理解这四个函数的原因吧!嘿嘿!你肯定又会多学一招!
在Activity中:
大家是否知道,在setContentView(new MySurfaceView(this))后,此Activity中声明的View控件,
如:TextView为什么引用不到layout布局文件中的控件ID呢!初一看能够应用到,但是为什么编译就报空指针呢!原因:在setContentView(new MySurfaceView(this))后,此时的View变为了根视图了,虽然能应用到TextView对应的ID,但是我在MySurfaceView中根本就没有这个对象,所以就报空指针咯!解决办法:
View view = LayoutInflater.from(this).inflate(R.layout.passover, null);注:每解析一次都会产生不同的对象
然后你再引用没问题,使用自如了。
今天是咋们部门同事告诉我的,问题解决啦!
分享到:
相关推荐
LayoutInflater源码分析 inflate方法的区别
LayoutInflater.from(context).inflate()方法的调研
Android 中LayoutInflater.inflate()方法的介绍 最近一直想弄明白LayoutInflater对象的inflate方法的用法,今天做了实例。 android:layout_width=match_parent android:layout_height=200dp android:...
android inflate demo,方便新手使用,下载导入android studio就可直接运行,简单明了的展现inflate不同参数的区别
本文主要介绍Android 中Inflate 方法的用法, 在开发Android应用过程中,可以在程序中应用 Inflate()方法加载新布局,希望能帮助有需要的朋友
帮助你更好的理解LayoutInflate中的inflate方法,以后想怎么用怎么用
NULL 博文链接:https://lxmgfd.iteye.com/blog/979716
主要介绍了Android LayoutInflater.inflate源码分析的相关资料,需要的朋友可以参考下
Android LayoutInflater.inflate...我尝试在Google官方文档与网络上其他讨论中寻找有关的说明,而后发现许多人不但不清楚LayoutInflater的inflate()方法的细节,而且甚至在误用它。 这里的困惑很大程度上是因为Google
博客《ListView滑动删除实现之一——merge标签与LayoutInflater.inflate()》对应源码,博客地址:http://blog.csdn.net/harvic880925/article/details/45155965
Android 中LayoutInflater的使用
inflate这个方法总共有四种形式(见下面),目的都是把xml表述的layout转化为View对象。 其中有一个比较常用,View inflate(int resource, ViewGroup root),另三个,其实目的和这个差不多。 int resource,也就是...
LayoutInflater在开发中使用频率很高,但是一直没有太知道LayoutInflater.from(context).inflate()的真正用法,今天就看看源码的流程。 首先来看from()的源码: /** * Obtains the LayoutInflater from the ...
主要介绍了Android LayoutInflater分析的相关资料,需要的朋友可以参考下
Android 中LayoutInflater(布局加载器)之实战篇 博客的Demo 博客地址: http://blog.csdn.net/l540675759/article/details/78112989 两种方式实现小红书的引导页: (1)自定义View (2)自定义LayoutInflater....
LayoutInflater Layout 与 Inflater[扩充]两个单词的合并,可以理解为:当前Activity 布局的扩充.