2013-07-30 234 views

回答

4

在运行时,您可以使用吹气,例如:

Inflater inflater = LayoutInflater.from(this); 
View view = inflater.inflate(R.layout.intro_step1_activity, null); 

,那么你可以将此视图添加到当前视图层次结构。在编译的时候,你可以使用包括标签的XML

<include layout="@layout/intro_step1_activity"/> 
+0

从Android文档: 这是从未直接使用。相反,使用getLayoutInflater()或getSystemService(String)来检索标准的LayoutInflater实例,该实例已经连接到当前上下文并正确配置了您正在运行的设备。例如: LayoutInflater inflater =(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); – LightMan

0

先举个idLinearLayout,然后定义在Java LinearLayout并使用findViewById()方法引用它。

然后使用刚刚创建的LinearLayout对象调用addView()方法。

如果你想要一个例子,评论。

0

是的,可以使用<merge><include>

你可以阅读更多herehere

3
Load an existing xml layout file in another xml layout file 

使用XML文件中的其他XML文件使用<include />

intro_step1_activity.xml使用代码

<include layout="intro_step1_activity.xml"/> 
相关问题