mazinthebox
mazinthebox

Reputation: 1

Android: Tips on CameraPreview

I managed to create the class that allows me to have a preview of the room (which is supported by a SurfaceView), and thus far everything is ok, the code work. Now I was wondering if it was possible to create buttons (or more generally any other object) on this Surface.

I tried to load the layout with setContentView (my_layout) but doing so is not loaded (or at least, not shown) the SurfaceView object. So as I seemed to understand, you can only load one of the two, or maybe I missing something?

Sorry for that bad English, but this text was generated by Google Translate.

Upvotes: 0

Views: 95

Answers (2)

Alexander
Alexander

Reputation: 48252

You can create a layout with transparent background and put it above your surface view.

Good thing is to create a FrameLayout with 2 elements in it. 1st being your SurfaceView with match_parent for both width and height so it occupies the whole parent FrameLayout.

2nd would be your layout with transparent background which can occupy, for example, part of the parent FrameLayout.

So then your SurfaceView gets created first and above it there will be your transparent layout with buttons.

That could work for kind of control panel or something but if you want kind of augmented reality you can have a look at the OpenCV SDK for Android where they do change the camera preview picture applying filters to it etc.

Upvotes: 0

blganesh101
blganesh101

Reputation: 3695

What you need to do is to create a framelayout and add buttons. Or construct your view with addContentView

LayoutInflater inflater = getLayoutInflater();
getWindow().addContentView(inflater.inflate(R.layout.main, null), new     ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

Upvotes: 1

Related Questions