Reputation: 1008
I have a FrameLayout containing two SurfaceViews. One of them will show the camera preview, and the other is a custom surface view I use for drawing. Problem is the surface view does not show up. If I comment out the line where the camera starts preview, it does though, on the black background. This indicates me that the Surface view is positioned well, but I suspect that when the camera preview draws, something goes wrong.
The camera view:
public CameraView(Context context, AttributeSet a) {
super(context, a);
mHolder = getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
The custom view:
public InclinaisonGauge(Context context, AttributeSet attrs) {
super(context, attrs);
getHolder().addCallback(this);
getHolder().setFormat(PixelFormat.TRANSLUCENT);
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
run = true;
updateThread = new Thread()
{
public void run()
{
Canvas c = null;
final SurfaceHolder inclHolder = getHolder();
while (run) {
try {
c = inclHolder.lockCanvas();
if(c!=null)
{
synchronized (inclHolder) {
onDraw(c);
}
}
} finally {
// do this in a finally so that if an exception is thrown
// during the above, we don't leave the Surface in an
// inconsistent state
if (c != null) {
inclHolder.unlockCanvasAndPost(c);
}
}
}
}
};
And I use this very simple draw method on the custom view to make sure it is not a framerate issue
public void doDraw(final Canvas canvas, final boolean bigSize, float daDirection)
{
canvas.drawARGB(255, 255, 255, 255);
}
Has anyone experienced this?
Thanks
Upvotes: 2
Views: 6989
Reputation: 161
I don't think SurfaceViews are intended to be used as an overlay, but it is possible to achieve this behavior. What you have to do is when the SurfaceView class is created:
setZOrderMediaOverlay(true);
getHolder().setFormat(PixelFormat.TRANSPARENT);
Upvotes: 3
Reputation: 1008
Ok, if anyone else gets this, solution is to call this on the surfaceView
this.setZOrderMediaOverlay(true);
Upvotes: 7