在实际工作中,事先写好的布局文件往往不能满足我们的需求,有时会根据情况在代码中自定义控件,这就需要用到LayoutInflater-->用来获得布局文件对象的。
LayouInflater经常在BaseAdapter的getView()方法中用到,用来获取整个View并返回。
LayoutInflater有三种用法 :
(1)LayouInflater inflater = LayouInflater.from(this);
View layout = inflater.inflate(R.layout.main,null);
(2) LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.main,null);
(3) LayouInflater inflater = (LayouInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.main,null);