views:

2697

answers:

2

How do I write code which layouts UI elements (Buttons, etc) over camera preview on Android ?

+5  A: 

Put the SurfaceView in a container that allows for Z-axis layering, such as RelativeLayout or FrameLayout. Put the things to appear on top of the SurfaceView later in the XML -- later children of a parent will draw over top of earlier children in the parent.

Here is a project using a SurfaceView for video playback that demonstrates the technique. The same concepts should hold for a SurfaceView for camera preview.

Bear in mind that extra work needs to be done by Android to blend your widgets with the preview, so your preview frame rate may drop.

CommonsWare
A: 

I tried to post a working example but while trying to format the post, it cuts the important part out. Cannot make it post the text.

So.... the preview is done on the surface view. The background color of the relative layout matters.

Use a RelativeLayout with android:background = "#00000001" Inside it, a SurfaceView. Inside it a Button or whatever control.

Mail me if you want the code, it won't show here.... Regards

Ari

BeMeCollective