I've used the example guide to create a class called CameraPreview which inherits from the SurfaceView class, and which displays the camera preview. I've also created another custom view class called DrawOnTop which just inherits directly from View, and I use this for drawing text and other items on top of the preview. Each view class works fine on its own, but when I load both views into the activity, the CameraPreview always dominates and none of the objects or text from the DrawOnTop class appear on top of the camera preview.
Because I'm using two custom view classes, I'm not bothering to inflate any view classes from XML in the activity's onCreate, so the onCreate doesn't contain any call to setContentView(...). Instead, I instantiate each view class, and load each view object into the activity's root view using addContentView(...), i.e.
CameraPreview preview = new CameraPreview(this);
addContentView(preview, new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
DrawOnTop drawontop = new DrawOnTop(this);
addContentView(drawontop, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
drawontop.setVisibility(View.VISIBLE);
drawontop.bringToFront();
I had a look at the activity's root view, and it turns out to be of type FrameLayout. As I said above, this methodology works fine for each view on its own.
To get the DrawOnTop class to appear on top of the camera preview, I've tried using bringToFront() but it doesn't have any effect. I'm testing the app on a Samsung Galaxy Note 2 LTE running Android Version 4.1.1.
Can anyone tell me what I'm doing wrong?