Tag usage in Android

Source: Internet
Author: User

The purpose of this Code is to improve the reusability of the Code. It can regard a defined layout as an element of another layout.

The following is an example:

This is main. xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >    <TextView        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="@string/hello" /><include layout="@layout/include1"/><include layout="@layout/include2"/></LinearLayout>

Include1.xml

<? XML version = "1.0" encoding = "UTF-8"?> <Textview xmlns: Android = "http://schemas.android.com/apk/res/android" Android: text = "This is the first layout file! "Android: layout_width =" wrap_content "Android: layout_height =" wrap_content "> </textview>

Include2.xml

<? XML version = "1.0" encoding = "UTF-8"?> <Textview xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "match_parent" Android: layout_height = "match_parent" Android: text = "This is the first layout file"> </textview>

Note: The following two layout files are included in Main. xml. You can see the effect without adding other code in activity. java.

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.