Android performance optimization series-Understanding Overdraw

Source: Internet
Author: User

Android performance optimization series-Understanding Overdraw

Overdraw refers to the number of times that a pixel is drawn within a frame;
Theoretically, it is optimal to draw a pixel only once at a time. However, due to the stacked layout, some pixels are drawn multiple times, each painting will correspond to a set of drawing commands on the CPU and some operations on the GPU, so repeated painting of overlapping invisible elements will produce additional calculations, and Overdraw should be minimized.

The Android system provides the Overdraw measurement option. In the developer option-Debug GPU Overdraw (Show GPU Overdraw), open the option to view the Overdraw status of the current page.

Based on the number of overdraw times, different colors are displayed to differentiate

Transparent = no overdraw blue = 1 layer green = 2 layers light-red = 3 layers dark red = you're doing it wrong Optimization Method

The general principle is to avoid overlapping invisible elements.

Remove unwanted background resources

Add in theme android:windowbackground="null"; Set getWindow (). setBackgroundDrawable (null) in Activity)
This method must be followed by setContentView () Because getWindow (). setBackground (Drawable) will show the setting of Drawable here to the background of DecorView. The default value is 0xff000000, and setContentView will initialize DecorView of phoneWindow for the first time;

Segment setting background
Sometimes Layout is configured with an overall background for convenience and a background for the sub-View. This also causes overlap. If the sub-View width is mach_parent, we can see that part of Layout is completely overwritten, here, you can set the background to reduce the re-painting.

View onDraw () method
You can use

Canvas. clipRect (); // crops canvascanvas. quickReject (); // determines whether the rectangular area is intersecting.
We recommend that you avoid Memory Allocation and object creation in the onDraw function, which will lead to frequent garbage collection and lower performance;
During initialization or animation clearance, reduce invalidate calls to keep layout flat as much as possible, and call requestLayout () as little as possible. requestLayout will cause the system to traverse the entire View tree and re-Remove measure and layout, if layout Nesting is complex, performance issues also occur. If the layout is complex, you can customize ViewGroup to handle the Reference

Android Performance Patterns: Understanding Overdraw
Android Performance Patterns: Invalidations, Layouts, and Performance

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.