Android development merge with include optimized layout _android

Source: Internet
Author: User

merge with include optimize the Android layout , the effect is not known, the use of personal feeling also has a lot of limitations, but still understand, recorded.

Layout files have root nodes, but excessive nesting in Android can cause performance problems, so when you use include nesting we use the 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 ">

 <textview
  android:layout_width=" wrap_content "
  android:layout_height=" Wrap_content "
  android:text= "John"/>

 <textview
  android:layout_width= "wrap_content"
  android:layout_height = "Wrap_content"
  android:text= "Dick"/>

 <textview android: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:tex t= "@string/hello_world"/> <button android:id= "@+id/toggle" android:layout_width= "Wrap_content" Android:layo
  ut_height= "Wrap_content" android:onclick= "OnClick" android:text= "Show/Hide"/> <viewstub android: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 big? Because the use of the space display in the merge will be displayed in the main layout file, such as my main layout is linearlayout and horizontal arrangement, then the elements in the merge are displayed in the horizontal arrangement, but if I want to let the elements of the merge vertical arrangement? Sorry, I can't do that.

Original link: http://blog.csdn.net/u012702547/article/details/47133647

This is the entire content of this article, I hope to learn more about Android software programming help.

Related Article

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.