RunLoop RunLoop - 7 months ago 39
Android Question

Include an existing XML layout file in another XML layout file

I have a LinearLayout defined in a file called intro_step1_activity.xml. I would like to load/reference this file in another xml file so that I do not need to retype the code in the other xml file. Is this possible and if so how can it be done?


At runtime you can use an inflater, for instance:

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

then you can add this view to the current view hierarchy. At compile time you can use the include tag for the xml

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