Android Notes (i)

Source: Internet
Author: User

1. Surfaceview is the inheritance class for view, which has a built-in surface for drawing. You can control the format and size of this surface. Surfaceview controls where this surface is drawn.
surface is a deep sort (z-ordered), which indicates that it is always behind its own window. The Surfaceview provides a visible area that is visible only on the surface portion of the visible area and not visible outside the visible area. The layout display of surface is affected by the view hierarchy, and its sibling view nodes are displayed at the top. This means that the content of surface is obscured by its sibling view, which can be used to place a cloak (overlays) (for example, text and buttons). Note that if you have transparent controls on your surface, each change will cause the framework to recalculate the transparency of its and top-level controls, which can affect performance.
you can get this interface by accessing the Surface,getholder () method through the Surfaceholder interface.
Surface is created when Surfaceview becomes visible, and surface is destroyed before Surfaceview is hidden. This will save resources. If you want to see when your surface is created and destroyed, you can reload surfacecreated (Surfaceholder) and surfacedestroyed (Surfaceholder).
the core of Surfaceview is the provision of two threads: the UI thread and the render thread. It should be noted here:
1> all methods of Surfaceview and Surfaceholder.callback should be called in the UI thread, which is generally the main thread of the application. The various variables to be accessed by the render thread should be processed synchronously.
2> because surface may be destroyed, it is only in SurfaceHolder.Callback.surfaceCreated () and SurfaceHolder.Callback.surfaceDestroyed () is valid, so make sure that the rendering thread accesses legitimate, valid surface.

Surfaceholder
2. A class Surfaceholder is used here, which can be used as a controller of surface to manipulate surface. Handle it on canvas to draw effects and animations, control surfaces, sizes, pixels, etc.
several methods to be aware of:
(1), abstract void Addcallback (Surfaceholder.callback Callback);
//Give Surfaceview the current holder a callback object.
(2), abstract Canvas Lockcanvas ();
//Lock the canvas, usually after it is locked, it can be drawn through canvas objects that it returns.
(3), abstract Canvas Lockcanvas (Rect dirty);
//Lock an area of the canvas for paint, etc... Since the drawing is finished, the following unlockcanvasandpost will be called to change the display.
//Relative part of the memory requirements of the relatively high game, you can not redraw the dirty outside the pixels of other areas, can improve speed.
(4), abstract void Unlockcanvasandpost (Canvas canvAs );
//End lock drawing, and commit changes.

Android Notes (i)

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.