Is there a way to include one resource in another (for example a header design in multiple activities’ layouts). I know I can add it at run time, can it be done in the XML?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes you can do this in XML. See the android docs
about merge/include
basically you would have 1 layout(
root.xml) as follows:and the
heading_layout.xml:so in your
Activityyou wouldsetContentView(R.layout.root);which would include the header.you can also do some cool stuff in addition to this programmatically, such as inserting a layout from xml into a the
root.xml(aftersetContentView();:where
rootLayoutis the parentRelativeLayoutfound by id andR.layout.homeis a layout you wish to add to the root