Android Development notes -- surfaceholder. Callback

Source: Internet
Author: User

1. Summary

First, you must briefly describe the relationship between surface and surfaceholder. callback.

Surface isAn important element of Android, used for drawing Android images. WhileSurfaceview is an inherited class of view. Each surfaceview encapsulates a surface. By calling surfaceholder, you can call surfaceview to control the image size and size. Surfaceholder is obtained through surfaceview. getholder. After creating a surfaceholder object, use surfaceholder. Callback () to call surfaceholder back and forth to control surfaceview.

It is a bit difficult to express in words, so the following section will be givenCodeFor understanding.

 

 Surfaceholder holder = (surfaceview) findviewbyid (R. Id.Camerapreview). Getholder ();

Holder. addcallback (This);

 

Holder. Settype (surfaceholder.Surface_type_push_buffers);

 

 

In this way, you can useCallback() PairSurfaceview.

IICallback() Method Introduction

Callback() Includes three functions:

①Surfacecreated(SurfaceholderHolder)

This function is called immediately after surface is created for the first time.ProgramYou can perform initialization related to the drawing interface in this function. Generally, the interface is drawn in another thread, so do not draw the surface in this function.

Parameters

HolderTheSurfaceholder

② Surfacechanged(Surfaceholder holder, int format, int width, int height)

This function is called when the surface state (size and format) changes. After surfacecreated is called, the function is called at least once.

Parameters

Holder updateSurfaceSurfaceholder

New format

New width

HeightNew Height

③ Surfacedestroyed()

This function is called before the surface is destroyed. After the surface function is called, it cannot continue to use the surface function. Generally, this function cleans up the resources used.

Parameters

HolderTheSurfaceholder

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.