我在名为 intro_step1_activity.xml 的文件中定义了一个 LinearLayout。我想在另一个 xml 文件中加载/引用此文件,这样我就不需要在另一个 xml 文件中重新键入代码。这可能吗?如果可以,如何实现?
最佳答案
在运行时你可以使用充气器,例如:
Inflater inflater = LayoutInflater.from(this);
View view = inflater.inflate(R.layout.intro_step1_activity, null);
然后您可以将此 View 添加到当前 View 层次结构中。在编译时,您可以使用 xml 的 include 标记
<include layout="@layout/intro_step1_activity"/>
关于android - 在另一个 XML 布局文件中包含现有的 XML 布局文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17955114/