最近自己做了个指南针应用,用到了SurfaceView。总结下Surfaceview与View的区别:
(因为写程序时是用英语写的注释和笔记,这里就贴英语的,但是本人英语不是很好。)
SurfaceView VS View
SurfaceView has an instance of Surface which can use OS background thread to
handle onto a raw buffer that is being managed by the screen compositor.
Because of Surface, SurfaceView has two main difference from View:
1. SurfaceView can draw canvas in background thread, not UI thread.
2. SurfaceView can use OpenGL(via Surface) which can draw 3D object
and use Hardware Acceleration to have a faster drawing.
Therefore, if we have to use 3D or high FPS(Frame per Second) performance,
use SurfaceView; otherwise use View.
Something about Surfaceview native code
Android graphic engine -- Skia -- main class type SkCanvas
View.invalidate() --- Android framework --- View.onDraw() --- Nativecode draw on SkCanvas
SurfaceHolder.lockCanvas() to get SkCanvas --- Nativecode draw on SkCanvas --- SurfaceHolder.unlockCanvasAndPost()
refer to: