Android: layout, rendering, memory leakage, response speed, listview and bitmap, thread optimization, and some optimization suggestions !, Androidlistview

Source: Internet
Author: User

Android: layout, rendering, memory leakage, response speed, listview and bitmap, thread optimization, and some optimization suggestions !, Androidlistview

1. Layout Optimization

First, Remove useless controls and layers in the layout, and then selectively use viewgroups with lower performance. For example, if RelativeLayout and LinearLayout can be used in the layout, we will use LinearLayout, because the functions of RelativeLayout are complex, the layout of RelativeLayout is costly.

Elegant CPU usage.

Another method of layout optimization is to use the <include>, <merge>, and <viewstub> labels. <Include> is mainly used for layout reuse. <include> and <merge> labels can be used together to reduce the layout hierarchy. <viewstub> ze provides the On-Demand Loading Function, yes

The layout in <viewstub> is loaded to the memory. This improves the initialization efficiency of the program. The following describes how to use them.

<Include>: Add <include layout = "@ layout/main_portals"/> in your root layout. Then, in the main_portals layout

<Merge xmlns: android = "http://schemas.android.com/apk/res/android"
Xmlns: hyhotel = "http://schemas.android.com/apk/res/com.hysmarthotel.movie">

// Add view as needed

</Merge>

Note: <include> labels only support attributes starting with android: layout. For example, android: layout_width and android: layout_height are not supported. For example, android: background and android: id are special cases, if this attribute is specified, the included layout is also specified

The ID. If the attribute android: layout _ * is specified, android: layout_width and android: layout_height must exist. Otherwise, other android: layout _ * will be invalid.

<Viewstub>: Usage

<ViewStub
Android: id = "@ + id/hotkey_view_stub"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: layout = "@ layout/hotkey_view_layout"/>

Add viewstub and hotkey_view_layout to your current layout. If you want to use this layout for the activity, you can load it in two ways. When ViewStub is loaded, viewStub will be replaced by its internal layout. In this case, ViewStub will not

This is part of the layout, and ViewStub does not support <merge> labels.

(ViewStub) findViewById (R. id. hotkey_view_stub). setVisibility (View, visibie); or

ViewStub viewStub = (ViewStub) findViewById (R. id. hotkey_view_stub). inflate ();

 

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.