Method for solving flicker problem of touch track drawn by Android surfaceview

This paper shares the methods to solve the flicker problem of surfaceview touch track for your reference. The specific contents are as follows

@H_ 502_ 3@ the first method to solve the flicker problem of surfaceview touch track:

Because surfaceview uses a dual cache mechanism, the two canvases are displayed on the screen in turn. In order to store the touch track and avoid the flicker problem caused by the inconsistent contents of the two canvases, you can completely solve the flicker by saving the drawing process and constantly re drawing. In addition, this also solves the occasional problem in many experiments because the moveto() function cannot read the parameters and execute the default settings (the parameters are set to the last touch point) The detailed code of the broken connection flashing problem is as follows:

It should also be noted that ArrayList saves the reference of the object, so you should create an object entity every time you add it.

@H_ 502_ 3 @ the second method to solve the flicker problem of surfaceview touch track:

When dealing with the drawing of touch screen track, surfaceview is used to establish the path object. When clicking, set the path object. Record the touch point during sliding, and reset the path object after leaving. Since the main thread cannot be blocked, a new sub thread is created to constantly refresh the screen, that is, draw the path continuously. However, then there is a problem: there is a small straight line segment flashing at the end of each track line on the screen. It is speculated that the object area obtained by lockcanvas () is different, so I tried to use lockcanvas (rect re), but it still hasn't solved the problem after running; Then I thought it might be because the objects obtained after each lockcanvas () are different, I added a canvas object to the main thread, modified the screen in the canvas object every time, and then submitted the display. However, the effect has not changed after the program runs! The program code is as follows:

The above is the whole content of this article. I hope it can help you easily solve the problem of touch track flicker in surfaceview.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>