LayoutInflater 是动态加载视图方式
加载方式有是个重载方法:
1. public View inflate(int resource, ViewGroup root)
2. public View inflate(int resource, ViewGroup root, boolean attachToRoot)
3.public View inflate(XmlPullParser parser, ViewGroup root)
4.public View inflate(XmlPullParser parser, ViewGroup root, boolean attachToRoot)
这四种使用方式中,我们最常用的是第一种方式,inflate方法的主要作用就是将xml转换成一个View对象,用于动态的创建布局。
虽然重载了四个方法,但是这四种方法最终调用的,还是第四种方式。第四种方式也很好理解,内部实现原理就是利用Pull解析器,
对Xml文件进行解析,然后返回View对象。
获取方式:
方式一 : LayoutInflater layoutInflater = getWindow().getLayoutInflater();
layoutInflater.inflate()
方式二 : LayoutInflater layoutInflater1 = this.getLayoutInflater();
layoutInflater.inflate()
方式三 :View inflate = View.inflate(); 直接返回一个View