Android uses include in Layout xml

Source: Internet
Author: User

In the Android layout style definition, you can use the XML file for easy implementation, sometimes for the reuse of modules, the include tag can be used to achieve this purpose. For example:

The description of the official website for Android development is here.
Among them, there are references to:

Similarly, you can override all the layout parameters. This means, any android:layout_* attribute can is used with the <include> tag.

This means that any android:layout_* attribute can be applied to the tag.

If you use the following code:

<Relativelayout    android:layout_width="fill_parent"    android:layout_height="wrap_content" >    <Textview        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="@string/somestring"        android:id="@+id/top" />    <include layout="@layout/otherlayout"        

includeThe discovery of the otherlayout, and not in the id/top as we expected under this textview, but ignores the Android:layout_below attribute. After Google's discovery, many people encounter similar problems.

A workaround is to wrap the linearlayout outside of the include, as follows:

<Linearlayout    android:layout_width="fill_parent"    android:layout_height="wrap_content"    android:layout_below="@id/top" >    

A better solution was found on the Statckoverflow: it must be overloaded with layoutwidth and layoutheight at the same time, and other layout_* properties will work, no this will be ignored. The above example should be written like this:

<include layout="@layout/otherlayout">    android:layout_height="wrap_content"    android:layout_width="fill_parent"    android:layout_below="@id/top" />

In addition, about the reuse of XML, you can also use the merge tag, the merge tag is mainly used to optimize the display, reduce the level of the view tree, you can refer to here: https://developer.android.com/resources/articles/ layout-tricks-merge.html, translated version here: http://apps.hi.baidu.com/share/detail/20871363

Original: Http://www.race604.com/using-include-in-layout/ref:

Android uses include in Layout xml
http://blog.csdn.net/race604/article/details/7564088

Use of the merge and include tags in android-xiabo852105 column-Blog channel-csdn.net
http://blog.csdn.net/xiabo851205/article/details/7841937

Android include and merge tag usage details-Shuqiaoniu blog-Blog Channel-csdn.net
http://blog.csdn.net/shuqiaoniu/article/details/46013771

Android uses include in Layout xml

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.