Camera preview UI overlay on Android?

Eli Ben-Ami picture Eli Ben-Ami · Dec 27, 2009 · Viewed 15.6k times · Source

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

Answer

CommonsWare picture CommonsWare · Dec 27, 2009

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.