I've created a custom camera view for Android. I have overlayed the camera preview with a semi transparent LinearLayout with a TextView and Button. Now I need to punch a 'hole' in the middle of the view so you can see the underlying camera preview cle开发者_如何学编程arly . The hole then acts as a frame guideline allowing the user to 'frame' the photo.
I succeeded with the iOS version by creating a view and cutting out a rectangle from the view as demonstrated here. How would I go about doing the same thing for Android?
Use SurfaceView.
"the SurfaceView punches a hole in its window to allow its surface to be displayed"
You're going to need to start with the hole and build around it. Layers in Android are additive, there is no way to punch a hole.
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 will allow the camera preview to show through.
精彩评论