Android View with a hole in it

I created a custom camera view for Android. I overlaid the camera preview on the translucent LinearLayout using TextView and Button. Now I need to punch a “hole” in the middle of the view so you can clearly see the camera’s preview. The hole then acts as a guide frame, allowing the user to "decode" the photo.

I was able with the iOS version to create a view and cut a rectangle from the view, as shown here . How will I do the same for Android?

+3
source share
3 answers

You will need to start with a hole and build around it. Layers in Android are additive, there is no way to punch a hole.

0
source

Use SurfaceView .

"SurfaceView punches a hole in its window to display its surface."

+3
source

This is the code I'm using:

setContentView(mCameraPreview);
addContentView(mOtherView, new LayoutParams
        (LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

Areas that are transparent in mOtherView let you preview the camera.

0
source

All Articles