Eli Ben-Ami
Eli Ben-Ami

Reputation: 499

Camera preview UI overlay on Android?

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

Upvotes: 17

Views: 15739

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006614

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.

Upvotes: 16

Related Questions