SurfaceView in ScrollView under 4.1

Here is the problem. For performance reasons, I prefer to use SurfaceView to draw a tabular form, and since this material is full of data, I use ScrollView as the parent of SurfaceView.

I am glad to see that it works fine on my personal mobile phone (HTC Desire HD 2.3.7), I tried to test it on one of the phones dedicated to the development of my company (Google Nexus S 4.1.?), And then my personal phone (HTC One X 4.1.1).

Something went wrong on the last two, my SurfaceView just went dark after scrolling ~ 80 pixels and got back to what it should look like when I scroll back under this size ~ 80 pixels (depending on screen size).

Trying to avoid this dimming, I tested some emulators ...

From 2.2 (customer desire) to 4.0.4, it works great.

The joke is under 4.2 ... it works too!

Definitely, it is only under 4.1.x that the SurfaceView goes black!

Here is my SurfaceView code that I just copied from the example you can find here .

public class MySurfaceView extends SurfaceView { public MySurfaceView(Context context, AttributeSet attrs) { super(context, attrs); // I use another SurfaceView behind to draw a grid // that is scroll independent with a white background this.setZOrderOnTop(true); // Same reason here this.getHolder().setFormat(PixelFormat.TRANSPARENT); this.getHolder().addCallback(this); this.getHolder().setSizeFromLayout(); // Tried without this line and with "software" and "none" types too // and hardware acceleration on application and activity this.setLayerType(View.LAYER_TYPE_HARDWARE, null); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawSomething()... } public void surfaceCreated(SurfaceHolder holder) { this.setWillNotDraw(false); this.thread = new MySurfaceViewThread(this.getHolder(), this); this.thread.setRunning(true); this.thread.run(); } public void surfaceDestroyed(SurfaceHolder holder) { this.thread.setRunning(false); boolean retry = true; while(retry) { try { this.thread.join(); retry = false; } catch(Exception exception) { Log.v(TAG, exception.getClass().getName(), exception); } } } } 
+4
source share
1 answer

This piece of code may be the answer

 if(VERSION.SDK_INT != VERSION_CODES.JELLY_BEAN) { this.setZOrderOnTop(true); } 

But the problem with this is that the background becomes black.

I need to draw the grid that I drew in the "background" of SurfaceView, on this one too for this particular version of Android.

This is not a good solution, because drawing this mesh in this SurfaceView violates the smoothness of scrolling and a pinch to zoom.

+3
source

All Articles