On Android layout optimization

Source: Internet
Author: User

In today's development environment, it is easy to forget to optimize the layout, we just need to adjust the adjustment in the IDE and then Setcontentview (), then let's see what he did in the process:

1. Reading files

2. Parsing data

3. Expand Layout

If the layout structure is complex, the longer it takes, then we might as well write a simple adjustment to the structure:

First, the use of relative layout

As a developer, the first thing we might be exposed to is linearlayout, because he is a default layout, and this layout is easier to use. For a long time we will find that a little copy of the structure with linearlayout words, will be nested deep, hierarchical structure is more complex, then we might as well use relativelayout

Second, the combined layout

Generally for the top level element for framelayout, because the activity of the content view is a framelayout, we might as well use the hierarchyviewer to see, If we just write framelayout, we'll find a framelayout on the top floor. If you replace framelayout with a <merge> expression, you'll find that there's less than one framelayout, which can play a role in reducing the hierarchy.

Third, Reuse layout

When it comes to reusing layouts, of course, it's a <include> tag, and many times with this there are two purposes, 1 are referenced multiple times in a layout, 2 Many files are common to a layout, the included layouts are dynamically processed, and are completed at compile time.

Iv. viewstub

This is a deferred initialization technology, he can not only improve performance but also save memory, some complex layout expansion takes time, but sometimes it is not necessary to expand at this time, we can consider using Viewstub to choose the right time to expand it, he has two ways of expansion

1.viewstub.inflate ()

2. Use Setvisibility () to expand it

Each has its own advantages, which one is suitable for use.

On Android layout optimization

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.