LayoutInflater 的使用,LayoutInflater 这个类非常有用,它的作用类似于 findViewById() ,不同点的是 LayoutInflater 是用来找layout 下 xml 布局文件,并且实例化!而 findViewById() 是找具体 xml 下的具体 widget 控件(如: Button , TextView 等)。
一般来讲,我们用 LayoutInflater 做一件事:inflate。inflate这个方法总共有四种形式,目的都是把xml 表述的layout 转化为View。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)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
A. Context.public abstract Object getSystemService (String name) :Return the handle to a system-level service by name. The class of the returned object varies by the requested name. 具体参见文档。