[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Reduce overdraw\n\nThis page explains what overdraw is, how to diagnose it, and ways to eliminate\nor mitigate it.\n\nWhen an app draws the same pixel more than once within a single frame, this is\ncalled *overdraw*. Overdraw is usually unnecessary, and it's best to eliminate\nit. Overdraw becomes a performance problem when it wastes GPU time to render\npixels that don't contribute to what the user sees on the screen.\n\nAbout overdraw\n--------------\n\nOverdraw refers to the system's drawing a pixel on the screen multiple times in\na single frame of rendering. For example, if you have a bunch of stacked UI\ncards, each card hides a portion of the one below it.\n\nHowever, the system still needs to draw the hidden portions of the cards in the\nstack. This is because stacked cards are rendered according to the [painter's\nalgorithm](https://en.wikipedia.org/wiki/Painter%27s_algorithm)---that\nis, in back-to-front order. This sequence of rendering lets the system apply\nproper alpha blending to translucent objects such as shadows.\n| **Note:** Although low-end devices continue to improve in GPU performance, their displays remain at relatively low resolutions. Unless optimizing for a known low-performance GPU device, we recommend instead focusing on optimizing UI thread work to help ensure smooth app performance. In addition to this, OS optimizations avoid overdraw within your app in many cases, such as a `Fragment` background overdrawing the window background.\n\nFind overdraw problems\n----------------------\n\nThe platform offers the following tools to help you determine if overdraw is\naffecting your app's performance.\n\n### Debug GPU overdraw tool\n\nThe Debug GPU Overdraw tool uses color-coding to show the number of times your\napp draws each pixel on the screen. The higher this count is, the more likely\nthat overdraw affects your app's performance.\n\nFor more information, see [Visualize GPU\noverdraw](/topic/performance/rendering/inspect-gpu-rendering#debug_overdraw).\n\n### Profile GPU rendering tool\n\nThe Profile GPU Rendering tool displays the time each stage of the rendering pipeline\ntakes to display a single frame as a scrolling histogram. The **Process**\npart of each bar, indicated in orange, shows when the system is swapping\nbuffers. This metric provides important clues about overdraw.\n\nOn less performant GPUs, available fill-rate---the speed at which the GPU can fill\nthe frame buffer---can be low. As the number of pixels required to draw a frame\nincreases, the GPU might take longer to process new commands and ask the rest of\nthe system to wait until it can catch up. The **Process** bar shows this spike\nhappens as the GPU gets overwhelmed trying to draw pixels as fast as possible.\nIssues other than raw numbers of pixels might also cause this metric to spike.\nFor example, if the Debug GPU Overdraw tool shows heavy overdraw and\n**Process** spikes, there's likely an issue with overdraw.\n\nFor more information, see [Profile GPU rendering\nspeed](/topic/performance/rendering/inspect-gpu-rendering#profile_rendering).\n| **Note:** The Profile GPU Rendering tool doesn't work with apps that use the NDK. This is because the system pushes framework messages to the background whenever OpenGL takes a full-screen context. In such cases, you might find a profiling tool provided by the GPU manufacturer helpful.\n\nFix overdraw\n------------\n\nYou can do the following to reduce or eliminate overdraw:\n\n- Remove unnecessary backgrounds in layouts.\n- Flatten the view hierarchy.\n- Reduce transparency.\n\nThis section provides information about each of these approaches.\n\n### Remove unnecessary backgrounds in layouts\n\nBy default, a layout doesn't have a background, which means it doesn't render\nanything directly by itself. However, when layouts do have backgrounds, they\nmight contribute to overdraw.\n\nYou can improve rendering performance by removing unnecessary backgrounds. An\nunnecessary background might not be visible because it's completely covered by\neverything the app is drawing on top of it. For example, the system might\ncompletely cover a parent's background when it draws child views on top of it.\n\nTo find out why you're overdrawing, look at the hierarchy in the [Layout\nInspector](/studio/debug/layout-inspector) tool. You can look for\nbackgrounds that aren't visible to the user and eliminate them. You can\neliminate unnecessary backgrounds wherever there are many containers that share\na common background color. You can set the window background to the main\nbackground color of your app and leave all containers above it with no\nbackground values defined.\n\n### Flatten the view hierarchy\n\nModern layouts help you stack and layer views to produce beautiful design.\nHowever, doing so can degrade performance by resulting in overdraw, especially\nin scenarios where each stacked view object is opaque, requiring the drawing of\nboth seen and unseen pixels to the screen.\n\nIf you encounter this issue, you might improve performance by optimizing your\nview hierarchy to reduce the number of overlapping UI objects. For more\ninformation about how to accomplish this, see [Performance and view\nhierarchies](/topic/performance/optimizing-view-hierarchies).\n\n### Reduce transparency\n\nRendering transparent pixels on screen, known as *alpha rendering*, is a key\ncontributor to overdraw. Unlike standard overdraw---when the system completely\nhides existing drawn pixels by drawing opaque pixels on top of them---transparent\nobjects require existing pixels to be drawn first, so that the right blending\nequation can occur.\n\nVisual effects like transparent animations, fade-outs, and drop shadows involve\nsome transparency, and can therefore contribute significantly to overdraw. You\ncan improve overdraw in these situations by reducing the number of transparent\nobjects you render. For example, you can get gray text by drawing black text in\na [`TextView`](/reference/android/widget/TextView) with a translucent alpha\nvalue set on it. However, you can get the same effect with better performance by\ndrawing the text in gray.\n\nTo learn more about performance costs that transparency imposes throughout the\nentire drawing pipeline, watch the video\n[Hidden Costs of Transparency](https://www.youtube.com/watch?v=wIy8g8yNhNk&index=46&list=PLWz5rJ2EKKc9CBxr3BVjPTPoDPLdPIFCE)."]]