Android Include tags use

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.