Android system provides View for drawing processing, View can meet most of the drawing needs, but in some cases, it is also not strong enough. We know that View is refreshed to reload. For drawing, the Android system redraws the screen by sending out the VSYNC signal. The refresh time is 16ms. If the view completes all the operations you want to perform within 16ms, then the user will not have a feeling of stuttering visually. And if the operation logic is too much, especially on the street that needs to be refreshed frequently, such as the game interface, it will continue to block the main thread and cause the screen to freeze. Many times you will see the warning “skipped xxx frames! The application may be doing too much” in the Log.
in order To avoid this problem, Android provides the SurfaceView component to solve this problem. SurfaceView can be said to be the twin brother of View, but it is still different from View. Mainly in the following points:
1. View is mainly suitable for active updates, while SurfaceView is mainly suitable for passive updates, such as frequent refresh.
2.View refreshes the screen in the main thread squadron, while SurfaceView usually refreshes the page through a sub-thread.
3. View does not have a double buffering mechanism when drawing, while SurfaceView has implemented a double buffering mechanism on the underlying implementation mechanism.
In short, if the custom view needs to be refreshed frequently, or if the refresh data processing volume is relatively large, then consider using SurfaceView instead of View.
p>
Android system provides View for drawing processing, View can meet most of the drawing needs, but in some cases, it is also powerful and insufficient. We know that View redraws by refreshing, and Android system sends The VSYNC signal is used to redraw the screen. The refresh time is 16ms. If the view completes all the operations you want to perform within 16ms, then the user will not have a feeling of stuttering visually, and if the operation logic is executed Too much, especially on the street that needs to be refreshed frequently, such as the game interface, then it will continue to block the main thread, causing the screen to freeze. Many times you will see the warning “skipped xxx frames! The application may be doing too much” in the Log.
in order To avoid this problem, Android provides the SurfaceView component to solve this problem. SurfaceView can be said to be the twin brother of View, but it is still different from View. Mainly in the following points:
1. View is mainly suitable for active updates, while SurfaceView is mainly suitable for passive updates, such as frequent refresh.
2.View refreshes the screen in the main thread squadron, while SurfaceView usually refreshes the page through a sub-thread.
3. View does not have a double buffering mechanism when drawing, while SurfaceView has implemented a double buffering mechanism on the underlying implementation mechanism.
In short, if the custom view needs to be refreshed frequently, or if the refresh data processing volume is relatively large, then consider using SurfaceView instead of View.