Android development merge with include optimized layout

Source: Internet
Author: User

Merge with include to optimize Android layout, the effect is not known. There are also very large limitations in the use of personal feelings. It's just a little bit more. Record them.

Layout files have root nodes, but too many nesting of layouts in Android can cause performance problems, so when using include nesting we can 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 will be actively nested into the following files when 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 bigger? The use of the space display in the merge is displayed as a main layout file. For example, my main layout here is linearlayout and horizontally arranged, so the elements in the merge appear to be arranged horizontally, but I suppose I want to arrange the elements in the merge vertically. Sorry, I can't do that.

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.