The include tag in the Android layout uses

Source: Internet
Author: User

The include tag in the Android layout uses

Recently in the layout, there are a lot of pages are common features, such as the title: a similar style!

As shown in the following:

If you give each page a separate title layout that would be too much trouble, if you can write a title layout, other pages reuse that much better!
This time, <include> it is a grand debut!

Write a title for the layout title.xml :

<?xml version= "1.0" encoding= "Utf-8"?><relativelayout xmlns:android="Http://schemas.android.com/apk/res/android" android:layout_width="Match_parent"android:layout_height="Wrap_content" android:background="@drawable/navigation_bar" >                <ImageViewandroid:id="@+id/img_backward"android:layout_alignparentleft ="true"android:layout_centervertical="true"android:layout_marginleft= "25DP" android:layout_gravity="center"android:layout_width="Wrap_content" android:layout_height="Wrap_content"android:src="@drawable/backward" />                                                                    <TextView        Android:id="@+id/tv_title"        Android:layout_width="Wrap_content"        Android:layout_height="Wrap_content"        android:textsize="20SP"        android:gravity="Center"        android:layout_centerinparent="true"        android:layout_gravity="Center"        Android:textcolor="@color/white"        Android:text="@string/tiltename"/></relativelayout>

On top of a few other similar pages <include> title.xml :

<linearlayout xmlns:android="Http://schemas.android.com/apk/res/android"  Xmlns:tools="Http://schemas.android.com/tools"android:layout_width="Match_parent"  android:layout_height="Match_parent"android:orientation="Vertical" >                    <!--titles --    <includeandroid:id="@+id/title_res"layout="@layout/title" / >                    <!--interface Content --    <framelayoutandroid:id="@+id/app_content"android:layout_width= "Match_parent" android:layout_height="match_parent" />                        </linearlayout>

It is important to note that in Google's official documentation there is a <include ...> last word:

However, if you want-to-override layout attributes using the tag, you must override both Android:layout_height and Android : Layout_width in order for other layout attributes to take effect.

The meaning is:

If you want to <include ...> use attributes in a tag layout_** , you must include and in the tags include android:layout_height android:layout_width , otherwise the layout_** properties will not take effect!

Summarize

In short, the label is to reuse the existing layout, no need to write redundant code! ———— multiplexing Layouts

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The include tag in the Android layout uses

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.