1, when to use: when the custom view needs frequent refresh, or refresh the data is relatively large, it is recommended to use Surfaceview instead of using the view
2. Steps to inherit Surfaceview: ①, Inherit Surfaceview class ②, Inherit Sufaceholder.callback interface, and runnable interface override the following methods
③, get Surfaceholder and join the callback interface
④, when surfacecreated () is callback, the thread is started
Public void surfacecreated (Surfaceholder holder) { new Thread (this). Start (); }
View Code
⑤, set a while () loop in the Run () method, and always draw the view
Public void run () { while (isdrawing) { draw (); // always draw }}
⑥, get the canvas provided by Surfaceview (see)
Public void Draw () { try{ = Mholder.lockcanvas (); } Catch (Exception p) { }finally{ mcanvas.unlockcanvasandpost (Mcanvas);} }
View Code
Surfaceview's Supplement