LayoutInflater在Android中是“擴展”的意思烟央,作用類似于findViewById()坑傅,不同的是LayoutInflater是用來獲得布局文件對象的唠亚,而
findViewById()是用來獲得具體控件的盖文。LayoutInflater經(jīng)常在BaseAdapter的getView方法中用到砍濒,用來獲取整個View并返回。
LayoutInflater的用法有三種:
第一種方法:
[java]view plaincopy
LayoutInflater?inflater?=?LayoutInflater.from(this);
View?layout?=?inflater.inflate(R.layout.main,null);
第二種方法:
[java]view plaincopy
LayoutInflater?inflater?=?getLayoutInflater();
View?layout?=?inflater.inflate(R.layout.main,null);
第三種方法:
[java]view plaincopy
LayoutInflater?inflater?=?(LayoutInflater)?getSystemService(LAYOUT_INFLATER_SERVICE);
View?layout?=?inflater.inflate(R.layout.main,null);