I got this working by having 2 transparent views over the SurfaceView camera using the following approach:
My activity sets all of its views in the onCreate() method, I do not use any layout file for this. It looks like this:
protected void onCreate(Bundle savedInstanceState) { super.onCreate(null); //savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); cameraPreview = new CameraPreview(this); addContentView(cameraPreview, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); animationView = new AnimationView(this); addContentView(animationView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); crosslinesView = new CrosslinesView(this); addContentView(crosslinesView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); }
cameraPreview is of type SurfaceView , animationView and crosslinesViews are of type View . onDraw() from the last two views is as follows:
protected void onDraw(Canvas canvas) { // Have the view being transparent canvas.drawARGB(0, 0, 0, 0); // Your drawing code goes here // ... }
Good luck
Lars blumberg
source share