If you have a large number of similar layout entries in an app, you can consider customizing the composite controls, or you can use the include tag. In my opinion, the include tag is considered to be somewhat simpler than the custom combo control. Custom composite controls not only inherit the control or inherit the layout, but also override some of the methods involved, sometimes customizing the properties file, and, if necessary, customizing the method to control the properties of the child control in the Java file. If the control is not good, the custom component will have an inexplicable error, such as the custom composite control instantiation failed, the property value failed to load or the property file could not be found.
So, in general, if it's not a particularly complex layout entry, I recommend the include tag.
Here's how to use the include:
First, you must recreate a title bar layout file, such as R.layout.title
Then use the <include layout= layout file name/>
If you want to control the title bar layout in the main layout, you must specify Android:layout_width and Android:layout_height. If you do not specify these two attributes, the title bar layout defaults to a certain location and does not allow you to control its location and size in the layout file or in the. Xml.
In this way, you can use the Findviewbyid (int id) to find the child controls in the title bar layout, as described above just adding a title bar layout
If you want to add multiple similar title bar layouts to a layout, use the include tag as well. However, multiple labels cannot find child controls and control their properties. So add an ID to the multi-label title bar layout and control its properties in the Java file with code.
Specific format: Findviewbyid (ID (layout title bar)), locate the label and add a reference to the label, transform the layout obtained by Findviewbyid (the layout title bar), and point the reference to the found label. Finally, you can use
Reference. Findviewbyid (int id) to query the child controls within the label. Of course, you can also control the position and size of the label by layout parameters.
Note: If you specify a specific size value for the label, the child controls are laid out according to the frame of the label. If the child control is too large to exceed the border of the label, the system does not display a portion outside the label frame, which affects the layout. So the layout label should first consider whether the label frame can wrap the child controls. Of course, setting the label to the package content wrap_content is a good choice, depending on the size of the child controls within the label to adjust the size of the label frame to fit the child controls, so that the sub-space can be fully displayed, to achieve the desired effect.
Android Include tags use