Android - SurfaceView flickers and sometimes doesn't apply the right paint

I have been experiencing this problem for quite some time, and even after I searched a lot of time, I did not find a reasonable solution to my problem.

The problem I'm experiencing is that SurfaceView I am using flicker. From time to time, the objects that I draw flicker, and they change their size or color.

It seems that sometimes the application skips my calls to "Paint.setColor ()", and another - "Paint.setStrokeWidth ()".

I created methods that change the paint used, and then, to try to fix this problem, return it to the default values. However, the problem persists. I also read that the problem may be due to double buffering. This is true? I use this code for DrawingThread:

PS. u may notice that I also tried to use a dirty rectangle to try to figure out if the problem can be fixed, but still nothing. [Perhaps I didn’t understand what this actually does]

class DrawingThread extends Thread { private SurfaceHolder _surfaceHolder; private CustomView _cv; private boolean _run = false; public DrawingThread(SurfaceHolder surfaceHolder, CustomView cv) { super(); _surfaceHolder = surfaceHolder; _cv = cv; } public void setRunning(boolean run) { _run = run; } public boolean isRunning() { return _run; } public SurfaceHolder getSurfaceHolder() { return _surfaceHolder; } @Override public void run() { Canvas c; while (_run) { c = null; try { //c = _surfaceHolder.lockCanvas(new Rect(lon - range, lon + range, lat - range, lat + range)); c = _surfaceHolder.lockCanvas(); synchronized (_surfaceHolder) { _cv.onDraw(c); } } finally { if (c != null) { _surfaceHolder.unlockCanvasAndPost(c); } } } } } 
+4
source share

Source: https://habr.com/ru/post/1402095/


All Articles