The Android platform provides a range of simple, reusable UI components known as widgets, but sometimes there may be larger or more complex UI components that you need to reuse across multiple screens, such as a panel containing a progress bar and a Cancel button, or a user profile consisting of a username and an avatar.
If your project features elements that you want to use multiple times, you can save yourself time and effort by implementing these elements as a reusable layout. You can then import these reusable elements into as many layout files as you want, using Android's >
and <merge/>
tags.
To extract common elements into a reusable layout, create a new XML layout resource file and then define the UI elements you want to reuse. Pay special attention to the file's root view as this will also be included every time you embed this component in other layouts.
To import your reusable component into a layout resource file, just add the...