SoFunction
Updated on 2025-04-10

Detailed explanation of Android View class and SurfaceView class

The main classes in Android game development are not only control classes but also display classes. The more important and complex ones are the processing of display and game logic. In J2ME, display can be achieved through Display and Canvas, while in Android, the display class is handled. The following is a brief introduction to you.

SurfaceView is a display class derived from the View base class. The direct subclasses include GLSurfaceView and VideoView. It can be seen that GL and video playback and Camera cameras generally use SurfaceView. What are the advantages? SurfaceView can control the format of the surface, such as the size and the position displayed in the screen. The most important thing is to provide the SurfaceHolder class, which is obtained using the getHolder method. The related ones include Canvas lockCanvas(), Canvas lockCanvas(Rect dirty) , void removeCallback(callback), void unlockCanvasAndPost(Canvas canvas) to control graphics and draw, and In the interface callback, you can define the specific implementation by yourself through the following three abstract classes (such as the first change of format and display screen):

       abstract void  surfaceChanged(SurfaceHolder holder, int format, int width, int height) ;

       abstract void  surfaceCreated(SurfaceHolder holder) ;

       abstract void  surfaceDestroyed(SurfaceHolder holder) ;

For Surface-related, the Android underlying layer also provides GPU acceleration function, so in applications with strong real-time performance, the main use of SurfaceView is not directly built from the View. At the same time, the GLSurfaceView in OpenGL that will be mentioned later is also implemented from this class.

The above is a detailed introduction to the Android View class and Surface class. I hope it can help Android development friends. Thank you for your support for this website and continue to add relevant information in the future.