In the case of the same layout (XML) When you write the Android program, we need to do some encapsulation in order to increase the reusability of the code, including two cases:
One: If you have a different layout that contains the same simple layout, you can extract code from the simple layout, such as: Mainactivity.xml and Setting.xml file, there is a titlebar layout, we can extract the titlebar, separate as a titlebar.xml file, and then where needed to use <include android:layout= "@ Layout.titlebar "/> Introduced
Second: If the included layout is relatively complex, you can populate it with one as a control, and for titlebar, all we need to do is define a subclass of ViewGroup, And in its construction method, forcing him to fill a layout in his own area (View.inflater (Context,r.layout.titlebar,this,false) where this represents the parent container, which is the component itself. So each time you load a view, it forces you to load a view style that you've set. Finally, you only need to write this view in the layout file.
Customizing a composite Control