Android linear Layout (linearlayout) Performance related

Source: Internet
Author: User

Android linear Layout (linearlayout) Performance related

The beautiful Life of the Sun Vulcan (http://blog.csdn.net/opengl_es)

This article follows "Attribution-non-commercial use-consistent" authoring public agreement

Reprint Please keep this sentence: Sun Vulcan's Beautiful Life-this blog focuses on Agile development and mobile and IoT device research: IOS, Android, HTML5, Arduino, Pcduino , Otherwise, the article from this blog refused to reprint or re-reproduced, thank you for your cooperation.


There are two performance issues in nested linear layouts as follows, can you find them without using Eclipse Adt hints?

<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:paddi ngbottom= "@dimen/activity_vertical_margin" android:paddingleft= "@dimen/activity_horizontal_margin" Android: paddingright= "@dimen/activity_horizontal_margin" android:paddingtop= "@dimen/activity_vertical_margin" tools:        context= "Com.mitest.linearlayoutexample.MainActivity" > <textview android:layout_width= "wrap_content"    android:layout_height= "Wrap_content" android:layout_weight= "1" android:text= "@string/hello_world"/> <linearlayout android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:l Ayout_id= "@+id/testlinearlayout02" android:layout_weight= "1" > <textview android:layout_wid Th= "Wrap_content" android:layout_height= "wrap_content"android:layout_weight=" 1 "android:text=" @string/hello_world "/> </linearlayout></li Nearlayout>

Here's the answer:

First place:


Replacing wrap_content with a layout-width value of 0DP will get better performance;


Second place:


The use of nested weights is detrimental to performance.

Linear layout nested a layer of linear layout, and both layers use the weight weight attribute to allocate the layout of the space, if this happens, the interface layout may be considered inappropriate, in my example, the relative layout is a good solution to the problem.

In short, a linear layout that can be replaced with a relative layout, should be a linear layout that can be used to avoid the use of Mian, slightly arbitrary, but will allow a lot of space for future expansion, and every time the interface layout changes, it is best to re-envision the use of various layout methods. Performance is no small matter, especially for Android!




Android linear Layout (linearlayout) Performance related

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.