Surfaceview, surfaceholder, surfaceholder. Callback of Android literacy

Source: Internet
Author: User

I recently came into contact with surfaceview, surfaceholder, and surfaceholder. Callback, but I have never asked them to solve them. Now I will give them a rough idea.

Let's take a look at the official definition:

1. surfaceview

Surfaceview is an inherited class of view, which is embedded with a surface dedicated for painting. You can control the format and size of the surface. Surfaceview controls the position of this surface.
Surface is ordered in depth (Z-ordered), which indicates that it is always behind its own window. Surfaceview provides a visible area where only the surface content in the visible area is visible and the area outside the visible area is invisible. The layout display of the surface is affected by the hierarchical view relationship, and its sibling view node is displayed at the top. This means that the content of the surface is blocked by its sibling view, which can be used to place overlays (for example, controls such as text and buttons ). Note: if there is a transparent control on the surface, every change to it will cause the framework to recalculate its transparency and the top-level control, which will affect the performance.
You can access this surface through the surfaceholder interface. You can get this interface through the getholder () method.
When surfaceview becomes visible, the surface is created. Before surfaceview is hidden, the surface is destroyed. This saves resources. If you want to check the time when the surface is created and destroyed, you can reload surfacecreated (surfaceholder) and surfacedestroyed (surfaceholder ).
The core of surfaceview is to provide two threads: the UI thread and the rendering thread. Note:
1> All surfaceview and surfaceholder. Callback methods should be called in the UI thread. Generally, they are applications.ProgramMain thread. Various variables accessed by the rendering thread should be processed synchronously.
2> because the 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 a valid surface.

2. surfaceholder

Displays an abstract interface of the surface, allowing you to control the surface size and format, edit pixels on the surface, and monitor surace changes. This interface is usually implemented through the surfaceview class.

3. surfaceholder. Callback

You can implement this interface to receive messages with changed surface. When used in a surfaceview,
It is valid only between surfaceholder. Callback. surfacecreated () and surfaceholder. Callback. surfacedestroyed. The method for setting callback is surfaceholder. addcallback.

 

After reading the official introduction, I have learned a lot about surfaceview with Z-order. You can also operate on the pixel with wood and separate rendering threads. If you want to develop games, you must select surfaceview.

 

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.