方法一
final View view = LayoutInflater.from(context).inflate(R.layout.test, null);
方法二
LayoutInflater li = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = li.inflate(R.layout.test,null);
//Activity2是activity,activity2是当前activity加载的layout
Context mContext = Activity2.this;
RelativeLayout rl = (RelativeLayout)LayoutInflater.from(mContext).inflate(R.layout.activity2, null);