Here is the problem.
For performance reasons, I choose to use a SurfaceView to draw a table-like form, and because this stuff is full of data I use a ScrollView as SurfaceView parent.
Happy to see it works fine on my personal development-dedicated phone (HTC Desire HD 2.3.7), I tried to test it on one of my company development-dedicated phone (Google Nexus S 4.1.?) and then on my personal phone (HTC One X 4.1.1).
Something went wrong on those two last ones, my SurfaceView just turned black after some ~80px scroll and turned back to what it should look like when I scrolled back under this ~80px (depends on screen size).
Trying to avoid this blackout, I tested under some emulators…
From 2.2 (customer’s wish) to 4.0.4, it works just great.
The joke is, under 4.2… it works too!
Definitely, that is only under 4.1.x that the SurfaceView turns black!
Here is my SurfaceView code, that I just copied from the sample 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);
}
}
}
}
This code snippet could be an answer
But the problem with doing this is that the background gets black.
I have to draw the grid I drawn in the “background” SurfaceView on this one too for this specific android version.
That is not a good solution, because drawing that grid in this SurfaceView breaks the smoothness of the scroll and the pinch-to-zoom.