//声明并实例化LayoutInflater LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View vi = inflater.inflate(R.layout.main, null); //vi就是main这个布局生成的View,在需要的地方添加使用