Custom Controls (2.2): SurfaceView and SurfaceHolder,
In this example, the requirement and process are as follows: The Activity loads the custom SurfaceView-> SurfaceView constructor to start thread A and cyclically change the x and y coordinates of SurfaceView. When x, when the y coordinate arrives at A certain point, set the gradient flag picAlphaFlag to true-> when the Surface is created, that is, surfaceCreated. Start thread B. The loop is based on x and y of SurfaceView (changed by thread A loop) when the position of the graph is drawn in real time and picAlphaFlag is true, the other graph is gradually displayed.
This example can be optimized (personal opinion): 1. Thread A and thread B can be merged;
Revelation in this example: 1. surfaceView is usually customized; 2. surfaceView is usually configured with more than one sub-thread to execute time-consuming operations such as drawing; 3. surfaceView usually implements SurfaceHolder. callback interface, mainly used to manage the life cycle surfaceCreated and surfaceDestroyed; Demo