第一种
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
inflater.inflate(...);//有多种构造函数
第二种
View inflate(Context context, int resource, ViewGroup root)
效果一
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
inflater.inflate(R.layout.list_item, null);
inflater.inflate(R.layout.list_item, null,false);
View.inflate(context,R.layout.list_item,null);
PS:这三种写法的效果是一样的,单纯的将布局塞到listview里面,所以根节点的属性并没有被使用.
效果二:
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
inflater.inflate(R.layout.list_item, parent, false);
其他写法:不推荐在recyclerView中使用
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
inflater.inflate(R.layout.list_item, parent, false);
inflater.inflate(R.layout.list_item, parent);
inflater.inflate(R.layout.list_item, parent, true);
View.inflate(context,R.layout.list_item,parent);