Android development merge with include optimized layout

Source: Internet
Author: User

Merge with include to optimize the Android layout, the effect is not known, the personal feeling there is also a lot of limitations, but still understand, recorded.

Layout files have root nodes, but too many nesting of layouts in Android can cause performance problems, so when using include nesting we use merge as the root node, which reduces layout nesting and increases the display rate.

<?xml version= "1.0" encoding= "Utf-8"?><merge xmlns:android="Http://schemas.android.com/apk/res/android" >    <TextViewandroid:layout_width="Wrap_content"android:layout_height= "Wrap_content" Android:text="Zhang San" />                            <TextViewandroid:layout_width="Wrap_content"android:layout_height= "Wrap_content" Android:text="John Doe" />                            <TextViewandroid:layout_width="Wrap_content"android:layout_height ="Wrap_content"android:text="Harry" />                        </Merge>

The above interface is automatically nested into the following file when it is displayed.

<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="Horizontal"  Tools:context="com.example.viewstub.MainActivity" >                        <include layout="@layout/top"/>    <textview  android:layout _width  = "wrap_content"  android:layout_height  = "wrap_content"  android:text  = "@string/hello_world" />     <button  android:id  = "@+id/toggle"  android:layout_width  =         "wrap_content"  android:layout_height  = "wrap_content"  android:onclick  = "OnClick"  android:text  =/>     <viewstubandroid:id="@+id/vs"android:layout_margin="50DP" android:layout_width="Match_parent"android:layout_height="Match_parent" Android:inflatedid="@+id/inflated_id"android:layout="@layout/view_stub_ Layout " />                                                </linearlayout>

Why do I say this limitation is relatively large? Because the use of the space display in the merge is displayed in the form of the main layout file, such as my main layout is linearlayout and horizontally arranged, then the elements in the merge are displayed horizontally, but if I want to arrange the elements in the merge vertically? Sorry, I can't do that.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced. If there is a wrong place, I would appreciate it if I could criticize it.

Android development merge with include optimized layout

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.